简单问题
#include<stdio.h>
int main()
{
char strCommand[5] = "stop";
while(1)
{
int i;
int j = 0;
for(i=0; i<4; i++)
{
if(getchar() == strCommand[i])
{
j++;
}
}
if(j == 4)
{
exit(0);
}
sleep(1);
/*printf("run\n");*/
}
exit(0);
}
这样可以停止程序。但注释打开后相应很慢,还要输出很多行“run”才停止。如何解决?