As soon as this program gets to the scanf line that has a precision specification, it jumps to the end of the program. I assume that a character is somehow getting into the subsequent scanf and getchar, but I don't see how that would happen. Can anybody tell me what is happening here? Also if I put a space between %lf and %*c it takes 2 enter presses to proceed and I don't know why that is either.
#define STORE_NAME "Sierra Sporting Goods"
int intNumber, intType, intQuantity;
double dblCost, dblPrice;
printf("%s\n", STORE_NAME); /*prompt for input*/
printf("\n\nEnter the product number: ");
printf("\nEnter the product type: ");
printf("\nEnter the quantity: ");
printf("\nEnter the cost: ");
scanf("%.2lf%*c", &dblCost); //<==== the .2 is my problem
printf("\nEnter the price: ");
scanf("%.2lf%*c", &dblPrice); //<==== the .2 is my problem
printf("\n\nThe product number is %d", intNumber); /*Display values*/
printf("\nThe product type is %d", intType);
printf("\nThe quantity type is %d", intQuantity);
printf("\nThe cost is %lf", dblCost);
printf("\nThe price is %lf", dblPrice);
printf("\nPress enter to continue\n");
%.2lf is not a valid conversion specifier for scanf. There is no precision on input, only output.
As to the other, a space in an input format string matches any and every whitespace, hence the first enter key would match the space and not the %*c.
Is that also to say that there is no width on input either(i have %04d in a scanf)?
Does "%04d" do something different than "%4d"?
You can have field width, sure. 04 is octal, and 4 is decimal, but in this case they both equal the same number. (0 doesn't mean anything special in scanf like it does in printf.)
On output only. Let's say x = 12;
printf("%d",x) produces 12;
printf("%04d",x) produces 0012;
The leading 0 will pad the output.