In the below program,i am not getting values from printf.
#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;
}
and this output I am getting
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 . . .
Why isn’t the output matching the input?
Too much copy and paste methinks. You are passing pointers when
printfexpectschars, same for the floats and ints.You passed the address of those variables to
scanfso that the function could change their value. When you use%d,%f, and%cprintfexpects an int (not a pointer to int), a float (not a pointer to float), and a char (not a pointer to char).