Code:
void deleteStaff() {
char ans;
int id, found;
FILE*fpo, *temp1;
fpo = fopen("Report", "rb");
temp1 =fopen("temp1", "wb");
printf("Enter the ID number you want to delete:");
scanf("%d", &id);
printf("Staff details:\n");
printf("ID\t NAME\n");
printf("============================");
while (fread(&sta, sizeof(sta), 1, fpo) !=0) {
if (id == sta.id) {
printf("%d\t\t%s\t%s\t%d", sta.id, sta.name, sta.position, sta.salary);
found = 1;
}
else
{
fwrite(&sta, sizeof(sta), 1, temp1);
found = 0;
}
}
fclose(fpo);
fclose(temp1);
if(found == 1) {
printf("Are you sure to delete : ");
scanf(" %c", &ans);
if (toupper(ans) == 'Y')
{
system("del Record");
system("rename temp1 Record");
printf("\nDeleted sucessfully....\n");
}
if (toupper(ans) != 'Y')
system("del temp1");
}
}
void displayStaff() {
FILE*fp1;
fp1 = fopen("Record", "rb");
printf("\n ID\t NAME\t POSITION\t SALARY\n");
while (fread(&sta, sizeof(sta), 1, fp1))
printf("%d\t\t%s\t%s\t%d", sta.id, sta.name, sta.position, sta.salary);
fclose(fp1);
}
void searchStaff() {
int id, found;
struct staff sta;
FILE*fp2, *temp;
printf("Enter the ID number you want to search:\n ");
scanf("%d", &id);
fp2 = fopen("Record", "rb");
temp = fopen("temp", "wb");
printf("Staff Details\n");
printf("ID NUMBERS\t NAME\n");
printf("=========================");
while (fread(&sta, sizeof(sta), 1, fp2) != 0)
{
if (id == sta.id) {
printf("%d\t\t %s\n", sta.id, sta.name);
found = 1;
}
else {
fwrite(&sta, sizeof(sta), 1, temp);
found = 0;
}
}
fclose(fp2);
fclose(temp);
if (found == 1)
system("Record");
}
}
whn i runthe display function, it wont displat the position ans name, gor delete function it trigger the break point when running the while line