简体   繁体   English

使用getline获取输入并检查C中是否为CTRL-D

[英]Using getline to get input and check if that is CTRL-D in C

im pretty new to c and bascially the problem im having is this currently i have this 我是C的新手,尤其是我现在有这个问题

  char* buf = (char*) malloc(sizeof(char) * MAX_LINE);
  size_t n=MAX_LINE;
  getline(&buf, &n, stdin);

How do i check buf in order to see when CTRL-D has been entered? 我如何检查buf以查看何时输入CTRL-D?

Thank you so much 非常感谢

^D will send an EOF on stdin. ^ D将在stdin上发送EOF。

From the manpage: 从联机帮助页:

   On success, getline() and getdelim() return the number of characters read, including the delimiter character, but not includ‐
   ing the terminating null byte.  This value can be used to handle embedded null bytes in the line read.

   Both functions return -1 on failure to read a line (including end-of-file condition).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM