允许用户搜索系统中的特定员工

时间:2017-12-08 14:20:29

标签: c

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("Staff", "rb");
temp = fopen("temp", "wb");
printf("Staff Details\n");
printf("ID NUMBERS\t NAME\n");
printf("=========================");
while (fread(&sta, sizeof(sta), 1, fp2) 
{
    if (id == sta.id) {
        printf("%d\t\t %s\n", sta.id, sta.name);
        found = 1;

    }
    else {
        fp2 = (NULL);
        printf("No such record!!");
        fwrite(&sta, sizeof(sta), 1, temp);
        found = 0;

    }
}
fclose(fp2);
fclose(temp);
if (found == 1) {
    system("Staff");
}
}

它将在while行中触发断点...但它不会显示结果。我如何解决它?它应该读取ID并显示结果。

0 个答案:

没有答案