也许第一段代码运行没有问题 但是,我输入评论数据后总是默认
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/