开发者

validate the input

开发者 https://www.devze.com 2023-02-19 23:49 出处:网络
Part of the code is as follows but not work printf(\"Ente开发者_如何学Pythonr a line of text (Enter to stop): \");

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

精彩评论

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