验证输入

时间:2011-03-24 08:26:52

标签: c

部分代码如下,但不起作用

  printf("Enter a line of text (Enter to stop): ");
  fflush(stdin);
  fgets(input, 256, stdin);

  if (input == '\0') {
    exit(0);
  }

  .....
  .....

我想如果用户只按Enter键,程序将被终止。怎么做? 感谢

1 个答案:

答案 0 :(得分:0)

使用if(*input == '\n') - 如果fgets读取换行符,则会将其存储在缓冲区中。