There are basically two things wrong with the section of code you showed that the compiler is complaining about:
- C is case sensitive:
struct book
and struct Book
are two different types.
- In C, you cannot refer to a type until it has been declared; that is, you cannot define a field of type
enum Stat
before you define enum Stat
.
The actual problem, then, is that the compiler doesn't know what a struct Book
is at the point where you try to define an array of them. Similarly, it doesn't know what an enum Struct
is at the point where you define a field of that type.
(Mostly unimportant tangent: The reason you are getting the "incomplete type" errors instead of something slightly more useful is because the compiler allows you, in certain cases, to use struct
types that you don't actually have the full definition of, but only if you use them through so-called "opaque" pointers (that is, you never actually use the type, you just pass pointers to them around.) In your case you are telling the compiler you want an array of struct Book
, which requires a completely define type, which you don't have.)
To fix it you just need to reorder your type definitions so that none of them are used before they're defined, and use consistent casing throughout. Also, while it's legal to continue to refer to struct foo
and enum bar
in the rest of your program, most people would create a typedef
(basically, type aliases) instead. For example:
typedef enum tagStat {
ACTIVE=1,
INACTIVE=2,
CHECKED_OUT=3,
CHECKED_IN=4,
UNDER_REPAIR=5,
LOST=6
} Stat;
typedef struct tagPerson {
char first[32];
char last[32];
Stat status;
} Person;
typedef struct tagBook {
char title[32];
char author[32];
int id;
int year;
int status;
} Book;
typedef struct tagLibrary {
Book collection[100];
Person patrons[100];
int totalBooks;
int totalPatrons;
} Library;