I'm having a problem with updating my C code on VS Code(version 1.77.0) and/or Code Runner extension for C language. The issue is that I have to run or recompile the code twice to get it up-to-date after modifying anything. The program is to append a keyboard input to a textfile. For example when I run the program it asks for the user's name then appends it to the output file. When I modify the fprintf function to add a newline after the name it adds the newline after I run the code twice.
#include <stdio.h>
int main()
{
FILE *fPointer;
fPointer = fopen("output.txt", "a");
char name[30];
printf("Please enter your name: ");
scanf("%s", &name);
fprintf(fPointer, "%s", name);
fclose(fPointer);
return 0;
}
I modified the fprintf(fPointer, "%s", name);
to fprintf(fPointer, "%s\n", name);
to get the user inputs in different lines in the output file.
I run the version of the program that doesn't add the newline character and input "myname" and get:
myname
on the output file. Then I modify the code to add a newline character when printing the user input to the output file.
#include <stdio.h>
int main()
{
FILE *fPointer;
fPointer = fopen("output.txt", "a");
char name[30];
printf("Please enter your name: ");
scanf("%s", &name);
fprintf(fPointer, "%s\n", name);
fclose(fPointer);
return 0;
}
After I run the new version for the first time and input "name2" I get
mynamename2
It should've been
myname
name2
Even though I change nothing and run the program again and input "name3",I get
mynamename2
name3
I tried playing with the autosave setting both for VS Code and the Code Runner extension, but those didn't really change anything. Manually saving is not working as well.