Reputation: 11
Im making a server client system in C using sockets, in my main program of the server, I create multiple threads to have multiple access to the server. I have a file where I store some informantion from the users, when the client disconects from the server, and before closing the thread I want to update the information on the file about that user, using a simple code of copying the file to a temporary file, deleting the main file and renaming the temporary file to the main file name. And I exit my thread.
Issue: The program is not able to delete the main file. But I tested it on the temporary file and it deletes.
I tested multiple things and Im not able to remove the main file, it is allways saying it is unable to delete it.
if (remove("ScoreBoard.txt") == 0)
printf("Deleted successfully");
else
printf("Unable to delete the file");
/* Rename temporary file as original file */
rename("replace.txt", "ScoreBoard.txt");
Upvotes: 0
Views: 90
Reputation: 535
Do you have the file open in another thread? Depending on your platform, that might prevent you from deleting the file.
Upvotes: 1