Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22015

Error Reading Values in a Array of Structures

$
0
0
struct book{    char name;    float price;    int pages;};struct book b[4];int i;for(i=0;i<4;i++){    printf("Enter name, price and pages in the book:\n");    scanf("%c %f %d", &b[i].name, &b[i].price, &b[i].pages);}

when I run the above code, it asks for all three variables only in first iteration and for the next iteration onwards I can only enter first value(i.e. char). I know there is something wrong with the float variable here since I am getting random huge values when trying to display it. How do I solve it and what actually is going on?

I using gcc on linux.

A detailed explanation is appreciated. Thank you.


Viewing all articles
Browse latest Browse all 22015

Trending Articles