Search code examples
ceclipsemacosscanfgets

Reading Input - gets scanf - Newbie


I am currently coding a program for an assignment involving customer orders... So far everything has been coded correct but now i have a problem when it comes to reading user input.. 2 lines are appearing on the screen without giving the user time to enter the order quantity.. This is because i am using scanf.. i tried making use of fflush(stdin) and get char() but none worked.. the following is the code which is giving me problems

puts("\nEnter Product Details\n");

puts("Product Name: ");

gets(newProduct.Name);

puts("ISBN: ");

gets(newProduct.ISBN);

puts("Description: ");

gets(newProduct.Description);

puts("Price: ");

scanf("%f",&newProduct.Price);

puts("Quantity in Stock: ");

scanf("%d",&newProduct.QuantityinStock);

printf("Supplier: ");

gets(newProduct.Supplier);

printf("Order Quantity: ");

scanf("%d",&newProduct.OrderQuantity);

Solution

  • You can try using getchar() after scanf()