c - 我不能用c语言从图书馆管理系统中删除书籍
问题描述
功能不是从文件中删除书籍,它应该删除所提供书籍的isbn编号,如果我们再次输入该isbn编号,如果书籍已被删除,它应该显示“找不到记录”的消息,而是再次显示信息书的ie文件没有被删除
void deletingbooks() //displaying only deleting books function
{
system("cls");
int d;
char findbook;
char another = 'y';
while (another == 'y') //infinite loop
{
system("cls");
printf("Enter the Book ID to delete:");
scanf("%d", & d);
fp = fopen("library.dat", "rb+");
rewind(fp);
while (fread( & info, sizeof(info), 1, fp) == 1) {
if (info.isbn == d) {
printf("The book record is available\n\n\n\n");
printf("Book name is %s\n\n", info.name);
printf("Author name is %c\n\n", info.Author);
findbook = 't';
}
}
if (findbook != 't') {
printf("No record is found modify the search\n\n");
if (getch())
mainmenu();
}
if (findbook == 't') {
printf("Do you want to delete it?(Y/N):\n");
if (getch() == 'y') {
fd = fopen("test.dat", "wb+"); //temporary file for delete
rewind(fp);
while (fread( & info, sizeof(info), 1, fp) == 1) {
if (info.isbn != d) {
fseek(fd, 0, SEEK_CUR);
fwrite( & info, sizeof(info), 1, fd); //write all in tempory file except that
} //we want to delete
}
fclose(fd);
fclose(fp);
remove("library.dat");
rename("test.dat", "library.dat"); //copy all item from temporary file to fp except that
fp = fopen("library.dat", "rb+"); //we want to delete
if (findbook == 't') {
printf("The record is sucessfully deleted\n");
printf("\nDelete another record?(Y/N)");
}
} else
mainmenu();
fflush(stdin);
another = getch();
}
}
mainmenu();
}
解决方案
推荐阅读
- c++ - 在 int 数组的情况下,新表达式可以“溢出”吗?
- openedge - 如何用今天计算昨天创建的记录?
- javascript - 使用 setInterval() 函数制作番茄钟
- html - Angular - 添加类的 CSS 属性未显示
- javascript - 如何从对象Javascript数组中检索花费的最高时间
- angular - 日期选择在 Firefox 中不适用于角度材料日期选择器
- android - 由于 SharedElementCallback,Google 登录失败
- python - 使用余数模运算符花费的 Python 时间
- laravel - 浏览器(黄昏)测试输入的 id 名称中的方括号
- python - Python - 检查字符串中嵌入了多少个字符串实例