What am I doing wrong? (struct) [closed]

1
struct book{
    char code[5];
    char title[30];
    char category[15];
    char author[30];
    float price;
};

struct book book[100];
book[0].price = 1;

It is giving error on the last line

    
asked by anonymous 06.06.2017 / 01:31

3 answers

0

You do not need the struct tag in the variable declaration.

#include <stdio.h>

int main(){
    struct book{
        char code[5];
        char title[30];
        char category[15];
        char author[30];
        float price;
    };

    book books[100];
    books[0].price = 1.0;
    printf("%f/n" ,books[0].price);
    return 0;
}
    
06.06.2017 / 02:02
0

Try declaring your struct as follows:

struct book{
char code[5]; 
char title[30]; 
char category[15]; 
char author[30]; 
float price; 
}sBook;

sbook book[100]; 
book[0].price = 1;

I hope I have helped!

    
06.06.2017 / 02:07
0

To resolve, change the name of the vector, for example, to books.

struct book books[100];

Then when assigning a value of 1 to a float, do this:

books[0].price = 1.0;
    
07.06.2017 / 08:12