My program won't write to the file after input is received. Everything else seems to work as expected.
Where have I gone wrong?
#include <stdio.h>
#include <unistd.h>
int main()
{
char fileSelectionInput[20];
printf("Select a file to print to: ");
gets(fileSelectionInput);
if (access(fileSelectionInput, F_OK ) == -1) {
puts("It seems that this file does not exist, sorry.");
return 0;
}
printf("Okay now you can type text to append\n\n");
FILE* testFile = fopen(fileSelectionInput, "w+");
int writesLeft = 10;
while (writesLeft > 1)
{
char textInput[50];
gets(textInput);
fputs(textInput, testFile);
writesLeft--;
}
fclose(testFile);
return 0;
}