Hi, i'm trying to understand structures so i tried with this example:
Code:
#include <stdio.h>
int main()
{
struct book {
char name;
float price;
int pages;
};
struct book b1, b2, b3;
printf("\nEnter names, prices, and number of pages of 3 books:\n");
scanf("%c %f %d", &b1.name, &b1.price, &b1.pages);
scanf("%c %f %d", &b2.name, &b2.price, &b2.pages);
scanf("%c %f %d", &b3.name, &b3.price, &b3.pages);
printf("\nAnd this is what you entered:\n");
printf("\n%c %f %d", b1.name, b1.price, b1.pages);
printf("\n%c %f %d", b2.name, b2.price, b2.pages);
printf("\n%c %f %d\n", b3.name, b3.price, b3.pages);
return 0;
}
the output is wrong though, the program lets me input only the data for the first and second books but not for the third, heres what happens:
Code:
Enter names, prices, and number of pages of 3 books:
a 234 234
b 243 235
And this is what you entered:
a 234.000000 234
0.000000 0
b 243.000000 235
can someone explain me why this happens? thanks!