Hi, I am a newbie in C, and I have just moved to the Structures Chapter in my text. This is the first program here.
Code:
#include<stdio.h>
int main()
{
struct book
{
char name;
float price;
int pages;
};
struct book b1,b2,b3;
printf("\nEnter names, prices, and no. of pages of 3 books.\n\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("\n\nAnd this is what you have entered.\n\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",b3.name,b3.price,b3.pages);
printf("\n\n\n");
return 0;
}
And the output:
Code:
Enter names, prices, and no. of pages of 3 books.
A 100 100
B 100 100
And this is what you have entered.
A 100.000000 100
-0.000029 134518560
B 100.000000 100
The compiler(GCC here) takes in the values of only two struct variables b1 and b3. I don't think anything is wrong with my code as I have copied it from the text.