void del() {
int temp = checker;
char search[30];
printf("Please enter the book name to be removed : ");
scanf_s("%[^\n]s", search, 30);
//fgets(search, 30, stdin);
for (int i = 0; i < checker; i++) {
if (strcmp(search, bookshelf[i].name) == 0) {
for (int j = i+1; j < checker; j++) {
strcpy_s(bookshelf[i].name, 31, bookshelf[j].name);
strcpy_s(bookshelf[i].semi_ISBN, 5, bookshelf[j].semi_ISBN);
bookshelf[i].page = bookshelf[j].page;
i++;
}
checker--;
printf("%s is removed from your bookshelf.\n\n", search);
}
}
if(temp==checker)
printf("%s is not in your bookshelf.\n\n", search);
}
这是我的代码,出于某种原因,当我尝试使用scanf_s或fgets时,显示的结果是: “请输入要删除的书名:儆儆儆儆儆儆儆儆儆儆儆儆儆儆儆儆儆儆不在书架上。” 一旦我运行该功能(没有输入任何东西)。
可能有什么不对......?