I'm writing a program that asks the user to enter information about a book or series of books (title, author, year, version and price) which are store inside a structure. So this is my structure
Code:
typedef struct {
char subject[MAXIMUM_TITLE];
char author[MAXIMUM_AUTHOR];
int year;
int edition;
float price;
} book;
I'm using it inside a function to enter the data like this
Code:
book getbookinfo(void){
printf("enter the name of the subject: ");
scanf("%c", &book.subject);
printf("enter the author: ");
scanf("%c", &book.author);
printf("enter the year of the book: ");
scanf("%d", &book.year);
printf("enter the edition you want");
scanf("%d", &book.edition);
printf("enter the price for the book: ");
scanf("%f", &book.price);
return book;
}
when I compile it I receive some errors
Code:
nventory.c: In function ‘getbookinfo’:
inventory.c:8: error: expected expression before ‘book’
inventory.c:11: error: expected expression before ‘book’
inventory.c:14: error: expected expression before ‘book’
inventory.c:17: error: expected expression before ‘book’
inventory.c:20: error: expected expression before ‘book’
inventory.c:22: error: expected expression before ‘book’
I don't understand why
Also I have another function that will look for a book based on either the year of the book or the price entered by the user.
Code:
searchresult searchbook(book inventory[MAXIMUM_BOOKS], int size, int option, int value){
28
29 int i, j, matches;
30
31 if(option==0){
32 for(i=0; i<size;i++){
33 if(value==inventory[i].year){
34 searchresult.booksfound[i] = inventory[i];
35 searchresult.searchmatches = i;
36 }
37 }
38 }
inventory[] is just the values returned by the first function, size is the number of books, option is the option entered by the user (year or price) and the value to be searched. I have another structure for 'searchresult'
with this part I get more errors
Code:
inventory.c:34: error: expected identifier or ‘(’ before ‘.’ token
inventory.c:35: error: expected identifier or ‘(’ before ‘.’ token
I don't understand why I'm getting these errors, what am I doing wrong?
I would like some help on this
thanks in advance