void returning()
{
char returned_date[50];
int i;
char returned_name[50];
char returned_author[50];
printf("Please enter the name of the book being returned and its author ");
scanf("%49s %49s",returned_name, returned_author);
do
{
if((strcmp(lib_books[i].name,returned_name)!=0)&&(strcmp(lib_books[i].author,returned_author)!=0))
{
i++;
printf("Unfortunately, there is no book by this name, Search again");
}
else
{
if(strcmp(lib_books[i].status,"returned")!=0)
{
strcpy(lib_books[i].status,"returned");
printf("Please enter the date returned");
scanf("%s",returned_date[50]);
if( returned_date== lib_books[i].returned)
{
printf("The book was returned on time");
strcpy(lib_books[i].returned, "0");
strcpy(lib_books[i].borrowed,"0");
lib_books[i].amt_days=0;
}
else
{
prices(i);
strcpy(lib_books[i].returned, "0");
strcpy(lib_books[i].borrowed,"0");
lib_books[i].amt_days=0;
}
printf("You have succesfully changed the status of a book!");
}
else
{
printf("This book has already been returned");
}
}
}while(strcmp(lib_books[i].status,"returned")!=0);
menu();
}
请参阅随附的屏幕截图,了解我的体验。它将在接下来的30分钟内到期。我是新手,不习惯这样做,请你帮我找到问题! After I enter the name of the book and the author this occurs:
答案 0 :(得分:0)
以下情况需要改变:
while(strcmp(lib_books[i].status,"returned")!=0);
如果lib_books
中的所有图书的状态均为"returned"
,则会进入无限循环。请更新此条件以检查i
是否已达到lib_books
中的最大元素。这应该至少解决你的无限循环和打印问题。