I am trying to run a basic program of structures
code
screenshot
ImageShack® - Online Photo and Video Hosting
code
Code:
#include<stdio.h>
int main()
{
struct book
{
char name;
float price;
int pages;
};
struct book b1,b2,b3;
printf("enter the value\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("entered values are\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;
}
It is taking iput for only 2 elements(it should for 3) and displaying correctly only first element. Garbage value is displayed for second element
screenshot
ImageShack® - Online Photo and Video Hosting