void playerdelete(int del){
FILE *plr;
FILE *extra;
int is_found = 0;
plr = fopen("User.dat", "rb");
extra = fopen("temp.dat", "wb");
while(fread(&player, sizeof(struct user), 1, plr) == 1){
if(player.id != del) fwrite(&player, sizeof(struct user), 1, extra);
else is_found = 1;
}
fclose(plr);
fclose(extra);
if(is_found == 0){
printf("nID not found.");
remove("temp.dat");
}
else{
if (remove("User.dat") != 0) {
perror("Error deleting User.dat");
}
else {
printf("User.dat deleted successfullyn");
}
if (rename("temp.dat", "User.dat") != 0) {
perror("Error renaming temp.dat to User.dat");
}
}
}
im using this same method for all other file related functions in the program
the code works well in online compilers, but i need it to work on code blocks specifically
the file itself is in the c directory, i’ve tried changing it from read only mode, and it still does not work
there is another question that is similar to mine, however, the answers on it do not solve my issue
New contributor
Box God is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.