gpt4 book ai didi

c - 输入数据后开关总是默认

转载 作者:太空宇宙 更新时间:2023-11-04 06:15:06 25 4
gpt4 key购买 nike

也许第一段代码运行没有问题但是,我输入评论数据后总是默认

char answer;

do{
printf("Do you want to add new comment?Y/N: ");
scanf("%c",&answer);
fflush(stdin);

switch(tolower(answer))
{
case 'y':
comment();
break;

case 'n':
main();
break;

default:
printf("Wrong choice !\n\n");
break;
}
}while(tolower(answer)!=='y'||'n');

有comment()的代码,我猜问题出在这里。

FILE*fp=fopen("comment.txt","a+");

if(fp == NULL)
{
printf("FIle not Found");
exit(1);
}
else
{
printf("Please enter your name: ");
gets(c.name);
printf("Pleas enter the date: ");
gets(c.date);
printf("Please enter the movie name: ");
gets(c.movie);
printf("Please enter your comment in 100 words:\n");
printf("Please press [Tab]and[Enter] to submit your comment\n");
scanf("%[^\t]",c.comment);

fprintf(fp,"%s %s\n%s\n%s\n\n",c.name,c.date,c.movie,c.comment);
}
fclose(fp);

有人可以帮帮我吗?谢谢!!

最佳答案

尝试使用 strlwr() 而不是 tolower()

关于c - 输入数据后开关总是默认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47592922/

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