gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:33:48 25 4
gpt4 key购买 nike

我对 C 还很陌生,基本上我遇到的问题是目前我有这个

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

如何检查 buf 以查看何时输入了 CTRL-D?

非常感谢

最佳答案

^D 将在标准输入上发送 EOF。

来自联机帮助页:

   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).

关于c - 使用 getline 获取输入并检查它是否是 C 中的 CTRL-D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23583480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com