开发者

validate the input

Part of the code is as follows but not work

  printf("Ente开发者_如何学Pythonr a line of text (Enter to stop): ");
  fflush(stdin);
  fgets(input, 256, stdin);

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

  .....
  .....

i want if the user only press enter, the program will be terminated. how to do it? thanks


Use if(*input == '\n') - if fgets reads a newline, it's stored in the buffer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜