I'm asked to create a SortType enumerated data type that stores two values, BY_TITLE and BY_YEAR. I'm then trying to implement a void addBookToList(SortType s, ListType *list, BookType *b) function that finds the new book’s correct insertion point in the list, based on the sort type indicated in the s parameter.
If the sort type is BY_TITLE, the book must be inserted in alphabetical order by title, and if the sort type is BY_YEAR, the book must be inserted in ascending order by year.
When I try to create the addBookToList function I keep getting the error:
expected declaration specifiers or ‘...’ before ‘SortType’ void addBookToList(SortType s, ListType *list, BookType *b)
I'm not sure if I'm declaring my SortType data type correctly and would appreciate some help.
defs.h:
Code:
enum sort{
BY_TITLE,
BY_YEAR
} SortType;
book.c
Code:
void addBookToList(SortType s, ListType *list, BookType *b){
if(s == BY_TITLE){
}
if(s == BY_YEAR){
}
}
I tried just changing the data structure in defs.h to:
Code:
enum SortType{
BY_TITLE,
BY_YEAR
};
and the error changed to 'unknown type name 'SortType'; did you mean 'ListType'? void addBookToList(SortType s, ListType *list, BookType *b)