This is what my code looks like now:
Code:
#include <stdio.h>
int main()
{
FILE *file1;
char thisChar[15];
char *p;
file1 = fopen("file1.txt","a");
printf ("Please enter a line of text, max %d characters\n",sizeof(thisChar));
fgets(thisChar, sizeof(thisChar)+1, stdin);
if ((p = strchr(thisChar, '\n')) != NULL) {
*p = '\0'; }
fprintf(file1,"%s",thisChar);
printf ("Written to the file.\n",thisChar);
}
BTW, is there a disadvantage to making file1 global?
If I DO set the size of fgets to 'sizeof(thisChar)', it only allows 14 characters, whereas the size of thisChar when declared is 15. I already knew this would happen as I had read it on another site - it said it will allow one less than the value declared in the second parameter of fgets().
Chris