0

Header file book_info struct

struct book_info {
         char title[50];
         char author[40];
         unsigned int year_published;
     };

typedef book_info;
book_info books[20];

void init_heap() {
    head = 0;
    for(int i = 0; i < 19; i++) {
            books[i].year_published = i+1;
        }
    books[20].year_published = 10000;
}

Trying to make an array of book_info structs, and then assign the year published of each struct to a number when initializing. Not sure exactly what the problem is?

3
  • What do you mean by typedef book_info;?? Commented Apr 2, 2015 at 6:20
  • books[20].year_published accesses out of bounds. The valid indices are 0 through 19. Commented Apr 2, 2015 at 7:13
  • Your question should include exactly what problem you are having (including the exact text of any compiler error/warning messages) Commented Apr 2, 2015 at 7:14

2 Answers 2

2

Instead of

typedef book_info;

you need

typedef struct book_info book_info;
Sign up to request clarification or add additional context in comments.

Comments

1

you can solve this problem by two ways.

1.typedef struct book_info book_info;

2.

struct book_info{
//...
    }books[20];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.