Could someone please tell me what's wrong with this code snippet? It runs perfectly well when compiled with MinGW, but selecting 'f' crashes the program when it is compiled with VS2010. I wasn't able to isolate the bug, but the files aren't removed or renamed.
Code:
case 'f':
case 'F':
write(); //calls write() if (f) is selected
/* verifies file closure */
if (fclose(f) != 0 || fclose(f_old) != 0)
{
printf("\nFile close error.");
return 1; //return error message
}
/* replaces original document with new one */
remove("database.txt"); //deletes original document
rename("database_temp.txt", "database.txt"); //renames document
return 0; //program exits normally
default: //returns error message if input is none of the above
printf("Invalid input.\n");
Here's the write() function:
Code:
int write ()
{
int i; //declares counter
/* cycles each seat variable to file */
for (i = 1; i <= 30; i++)
fprintf(f, "%s\n%s\n%s\n\n",
seat[i].no, seat[i].fname, seat[i].lname);
return 0; //returns to main function
}