I'm unable to find bug in this C program.
#include <stdio.h>
int main()
{
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b[3] ;
int i ; int k;
for ( i = 0 ; i <= 2 ; i++ )
{
printf ( "\nEnter name, price and pages: " ) ;
k = scanf ( "%c %f %d", &b[i].name, &b[i].price, &b[i].pages ) ;
}
for ( i = 0 ; i <= 2 ; i++ )
printf ( "\n%c %f %d", b[i].name, b[i].price, b[i].pages ) ;
//getch();
return 0;
}
run time:
Enter name, price and pages: a 1 1
Enter name, price and pages: b 2 2
Enter name, price and pages:
a 1.000000 1
7922540190797673100000000000000000.000000 4200368
b 2.000000 2
I wanted to give a 1 1
, b 2 2
, c 3 3
as my inputs for each scanfs but it didn't wait for my input in 3rd scanf. Why so? and why did it read my 2nd time input into 3rd elementof array?