binary - Cannot delete records from filing in C++ -
i coding little program university. want delete saved record of employee. when enter id of employee , delete it, seems have been deleted. when check record, still present there. can not figure out why. here code:
system("cls"); more = 'y'; while ((more == 'y')||(more == 'y')) { faculty = fopen("employee.txt","rb+"); temp = fopen("temp.txt","wb+"); rewind (faculty); cout<<"employee id: "; cin>>xid; while (fread(&em, empsize, 1, faculty) == 1) { if (xid != em.id) { fseek(temp, 0, seek_end); fwrite(&em, empsize, 1, temp); } else found=1; } fclose (temp); fclose (faculty); remove ("employee.txt"); rename ("temp.txt", "employee.txt"); if (found == 1) { //faculty = fopen("employee","rb+"); cout<<"delete record (y/n). "; cin>>more; } else { system("cls"); cout<<"\n\n\t\t\t\""<<xid<<"\" id not exist.\n\t\t\tdelete record (y/n). "; cin>>more; } if (more == 'n') { cout<<"\n\n\ttaking hr .. \n\t"; system("pause"); hr (); } } break;
before while loop need set value of found
other 1
. if delete record successfully, record deletion requests afterwards appear successful though weren't because found == 1
flag still set.
Comments
Post a Comment