在下面的程序中,我沒有從printf
得到值。visual studio中的struct程序
#include<stdio.h>
int main()
{
struct book
{
char name;
float price;
int pages;
};
struct book b1,b2,b3;
printf("enter names prices & no. of pages of 3 books\n");
scanf("%c %f %d",&b1.name,&b1.price,&b1.pages);
fflush(stdin);
scanf("%c %f %d",&b2.name,&b2.price,&b2.pages);
fflush(stdin);
scanf("%c %f %d",&b3.name,&b3.price,&b3.pages);
fflush(stdin);
printf("and this is what you entered\n");
printf("%c %f %d",&b1.name,&b1.price,&b1.pages);
printf("%c %f %d",&b2.name,&b2.price,&b2.pages);
printf("%c %f %d",&b3.name,&b3.price,&b3.pages);
return 0;
}
這個輸出我得到
enter names prices & no. of pages of 3 books
a 34.6 23
b 23.4 34
c 63.5 23
and this is what you entered
0.000000 0∞ 0.000000 0╪ 0.000000 0Press any key to continue . . .
爲什麼不輸出匹配輸入?
大多數'printf()'格式最後都需要換行符,除非您有意識地構建單個多行調用輸出到'printf()'。而且,如果不包含換行符或使用'fflush(stdout)'或'fflush(0)',則可能看不到輸出。 –