В приведенной ниже программе я не получаю значения от printf
.struct program in visual studio
#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)'. –