YES继续执行 NO则退出。。YES继续执行 NO则退出。。YES继续执行 NO则退出。。YES继续执行 NO则退出。。YES继续执行 NO则退出。。
如果输入的既不是YES也不是NO呢?
你的这个问题不完整啊。
还有,是不是需要区分大小写呢
以下这段代码,区分大小写的,同时,输入既不是YES也不是NO的时候,提示输入错误。
void DoYes()
{
// 做点想做的事
}
void InputError()
{
// 提示一下:输入错误了,不是YES也不是NO
}
int main()
{
char input[100];
while (true)
{
scanf("%s",input);
if ((strcmp("YES", input) == 0)
{
DoYes();
}
else if (strcmp("NO", input) == 0)
{
break;
}
else
{
InputError();
}
}
return 0;
}
用strcmp这个函数。判断返回值,自己百度百度就行了。
char czBuf[10];
gets(czBuf);
if (strcmp(czBuf,"YES"))
{
}
char input[10];
memset(input,0x00,sizeof(input));
puts("please enter the string of input: ");
scanf("%s",input);
if((strcmp("YES",input) == 0))
{
/*业务处理*/
} else if((strcmp("NO",input) == 0))
{
exit(0); /* 退出*/
}
char input[10];
memset(input,0x00,sizeof(input));
puts("please enter the string of input: ");
scanf("%s",input);
if((strcmp("YES",input) == 0))
{
/*业务处理*/
} else if((strcmp("NO",input) == 0))
{
exit(0); /* 退出*/
}
do()while循环可以实现先运行上面的函数再询问要不要求输入yes
新建线程可以实现等你想yes的时候执行函数,也不会让程序一直等你输入yes
const char *yes = "yes";
const char *no = "no";
if (strcmp(input, yes) == 0)
{
printf("same!");
}
strcmp()判断 返回0表示字符串相等