No. You're driving me nuts here.
Originally Posted by CS_Student8337
Info on fgets:
Let's not assume anything by checking one array element. That doesn't even sound right, does it?
char *fgets(char *s, int n, FILE *stream);
fgets reads characters from stream into the
The function stops reading when it reads
either n - 1 characters or a newline
character, whichever comes first.
fgets retains the newline character at the end
of s. A null byte is appended to s to mark the
end of the string.
On success, fgets returns the string pointed
to by s.
It returns null on end-of-file or error.
char string = "This is a test";
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(string)+1, stream);
/* display the string */
I'll read thru this thread and see what's up if you promise not to Rube Goldberg it to death.
OK, you've got your sizes wrong for fgets(). You want it to be two char *LESS* than the size of the array the user is putting char's into.
So, fgets() needs space in the char array for the char's you want entered, + one space for a newline, + one space for an end of string char marker.
So adjust your number of char's you want fgets() to put into the array, accordingly. (Two char's less than the size of the array)
Then see how if that doesn't work properly for you.