I am having problem with the following code; plz help.....
Code:
#include<stdio.h>
struct book
{
char name;
float price;
int pages;
};
main()
{
struct book b[10];
int i,n;
printf("\nEnter the no of entry\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter name ,price and pages");
scanf("%c%f%d",&b[i].name,&b[i].price,&b[i].pages);
}
for(i=0;i<n;i++)
{
printf("%c\n%f\n%d\n",b[i].name,b[i].price,b[i].pages);
}
}
IT OUTPUTS:
---------------------------------
Enter the no of entry
2
Enter name ,price and pages d 5 34
Enter name ,price and pages
-1.594697
12700610
d
5.000000
34
-----------------------------------
On entering values for the first instance of the structure it prints the msg "Enter name ,price and pages" but doesn't wait for me to enter values this time.. and prints ..
-1.594697
12700610
then it prints the values of the 1st instance... I m not being able to figure out whats happening... plz help