You need to read up on string operations in C. And pointers.
The following lines of code:
movieTitle[movieCount]=aMovie.title; movieTime[movieCount]=aMovie.time;
What do you think they do? Copy the strings? No. They copy pointers to strings. Then you go back into your loop and overwrite the strings (and whatever points to them will return the new stuff).
Try this:
movieTitle[movieCount]=strdup(aMovie.title); movieTime[movieCount]=strdup(aMovie.time);
That allocates new memory and stores a copy of your string in it. You should read up on memory allocation and leaking as well, but for what you pasted, this is probably good enough :D
EDIT:
A few more hints:
Incorrect: scanf("%s", &aMovie.title);
Correct: scanf("%s", aMovie.title);
Incorrect: scanf("%s", &aMovie.time);
Correct: scanf("%s", aMovie.time);
That's because char s[20]
is already a pointer to a pre-allocated 20 byte string. s is type char *
. &s
will be a pointer to the pointer. It will have type char **
.