void deleteCar() { CAR car; char findID[20]; printf("\n车辆信息输入\n"); printf("请输入要删除的车牌号:"); scanf("%s", findID); pFile = fopen("info.dat", "rb+"); rewind(pFile); int flag = 0; while(fread(&car,sizeof(CAR),1,pFile)){ if (strcmp(car.number, findID) == 0){ fla
时间: 2024-03-31 14:31:55 浏览: 91
void deleteCar() {
CAR car;
char findID[20];
printf("\n车辆信息删除\n");
printf("请输入要删除的车牌号:");
scanf("%s", findID);
pFile = fopen("info.dat", "rb+");
if (pFile == NULL) {
printf("文件打开失败!\n");
return;
}
rewind(pFile);
int flag = 0;
while(fread(&car,sizeof(CAR),1,pFile)){
if (strcmp(car.number, findID) == 0){
flag = 1;
fseek(pFile, -sizeof(CAR), SEEK_CUR);
CAR emptyCar = {"", "", "", ""}; // 定义一个空的CAR结构体,用于清空文件中的数据
fwrite(&emptyCar, sizeof(CAR), 1, pFile);
printf("删除成功!\n");
break;
}
}
if (flag == 0) {
printf("未找到该车辆信息,删除失败!\n");
}
fclose(pFile);
system("pause");
}
阅读全文