gpt4 book ai didi

c - 我该如何解决

转载 作者:行者123 更新时间:2023-11-30 21:07:41 25 4
gpt4 key购买 nike

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:

最佳答案

以下条件需要更改:

while(strcmp(lib_books[i].status,"returned")!=0);

如果lib_books中没有一本书的状态为“已返回”,这将进入无限循环。请更新此条件以检查 i 是否已达到 lib_books 中的最大元素数。这至少应该解决您的无限循环和打印问题。

关于c - 我该如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42641514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com