I have a function that saves some values in a file, and the user writes the name of the file, but how would I check if the file already exist? Is there any function that alerts the user about this?
This is the save function I use:
////////////////////////////////////////////////////////
void
save_project(void)
{
char file_name[8];
FILE *outp;
printf("Enter name of file in which to place results: ");
scanf("%s", file_name);
outp = fopen(file_name, "w");
fprintf(outp, "%.2f\n", LOA);
fprintf(outp, "%.2f\n", I);
fprintf(outp, "%.2f\n", J);
fprintf(outp, "%.2f\n", P);
fprintf(outp, "%.2f\n", E);
fprintf(outp, "%.2f\n", D);
fprintf(outp, "%.2f\n", GM);
fprintf(outp, "%.2f\n", H1);
fprintf(outp, "%.2f\n", H2);
fprintf(outp, "%.2f\n", H3);
fprintf(outp, "%.2f\n", S1);
fprintf(outp, "%.2f\n", S2);
fprintf(outp, "%.2f\n", S3);
fclose(outp);
printf("\n\nPress any key to continue");
getch();
project();
}
////////////////////////////////////////////////////////