从事有关预订系统的项目。此功能是删除文本文件中的一行。当我运行此程序时,什么也没发生。
CustomerD.txt用于记录所有删除预订的学生。 Backup.txt用于临时文件。
int del()
{
FILE *in, *out, *stay;
char ch, conf;
int temp = 0;
int id;
in = fopen("Customer.txt", "r");
out = fopen("Backup.txt", "w+");
stay = fopen("CustomerD.txt","w+");
if (in == NULL)
{
printf("\nCannot Open the Source file");
exit(1);
}
if (out == NULL) {
printf("\nCannot create Target File\n");
exit(1);
}
printf("Enter your id :");
scanf("%d", &id);
ch = fgetc(in);
while (ch!= EOF)
{
if (id!=s->id)
{
ch = fgetc(in);
fputc(ch, out);
}
else {
ch = fgetc(in);
fputc(ch, stay);
}
}
printf("Your Deletion is done");
fclose("Customer.txt");
fclose("Backup.txt");
fclose("CustomerD.txt");
remove("Customer.txt");
if (remove("Customer.txt") == 0)
printf("Deleted successfully");
else
printf("Unable to delete the file");
rename("Backup.txt","Customer.txt");
return 0;
}