Hi. First of all, I'm new to the forum, so it's very nice to meet all of you who are reading this.
I have some experience with Java programming, but I'm only now starting with C.
So like the title suggests, I'm having a little trouble with my struct arrays.
I'm just doing little programs to use as tests, so that I can get started on my bigger "homework" project.
First of all I got something like this:
Code:
typedef struct book { char title[MAX_TITLE];
char isbn[MAX_ISBN];
char authors[MAX_AUTHORS];
struct publisher * publ_ptr;
int year;
} Book[MAX_BOOKS];
typedef struct publisher {
char name[MAX_PUB_NAME];
Book * book_ptr[MAX_PUB_BOOKS];
int book_count;
} Publisher[MAX_PUBS];
So all the MAX limits stuff are already defined so no worries.
So next I was trying to just access the structures, so my first objective was to fill the string title, of the struct Book, from standart input.
So I did
Code:
fgets(&Book[1].title,MAX_LINE_CHAR, stdin);
printf("%s\n",Book[1].title);
So then I compile it in the console with
gcc -Wall -o Ex3.out Ex3.c
and I get the following errors
Ex3.c:38: error: expected expression before ‘Book’
Ex3.c:38: error: too few arguments to function ‘fgets’
Ex3.c:39: error: expected expression before ‘Book’
the error lines corresponding to the 2 lines of code that I posted.
And I know that the problem is in accessing the variable title, because I already tested the fget function with a normal char array and worked perfectly.
So can anyone enlighten me on what I'm doing wrong?
Thank you.