Trouble writing characters to a file.
I've been learning the C programming language for 2 days now (I'm fairly experienced with Javascript) and I have a problem with this code:
Code:
#include <stdio.h>
FILE *file1;
main()
{
char thisChar;
file1 = fopen("file1.txt","a");
printf("Type a character to print to the file. Type a slash / to exit: ");
labl:
scanf("%c",&thisChar);
if(thisChar=='/') {
goto the_end; }
else {
fputc(thisChar,file1);
}
goto labl;
the_end:
}
When I open file1.txt, every character which has been written to the file appears on a separate line. I want them to appear on a single line. What's going on? Any help much appreciated. I'm finding C very challenging, but I hope to eventually be fairly good at it.
Chris :)