用C语言编程:如果写入内部,则退出无限循环

时间:2016-12-09 18:15:07

标签: c while-loop exit-code

如果添加新关系,我需要退出此循环! 只要它是空的或按下“回车”,它就需要继续运行。

var startInfo = new ProcessStartInfo("myprogram.exe");
startInfo.Arguments = "do_admin_stuff";
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
Process.Start(startInfo);

输出:

CODE:
static char input[100];

int main()
{
  printf("Press Ctrl+c to Exit!\n");
  while(1)
  {
    //Input (stdin) and output (stdout) declared in <stdio.h> library
    fputs("esp>", stdout);
    fgets(input,100,stdin);

    if(input != 0) //here I can not change it !!!
      return 1;
  }
return 0; 
}

1 个答案:

答案 0 :(得分:2)

如果你只想检查空输入,试试这个吗?

while(1)
{
    fputs("esp> ", stdout );
    fgets( input, 100, stdin );

    if( input[0] != '\n' && strlen(input) )
    {
        // Do something with input
    }
}