gpt4 book ai didi

c - 尝试在 C 中使用 getLine() 读取 stdin 时出错

转载 作者:行者123 更新时间:2023-11-30 20:33:52 24 4
gpt4 key购买 nike

我正在使用 C 的这个函数通过 getLine() 函数读取用户输入(stdin)。此函数返回带有用户输入的 char*。这是片段:

char * rline(void)
{

char *line;
size_t buff = 0;
char * getLine(&line, &buff, stdin);
return line;

}

但是运行的时候却显示这个错误,并且无法编译。

error: expected declaration specifiers or '...' before '&' token    

我环顾四周,但不太明白为什么会发生这种情况,我的语法正确还是逻辑错误?

最佳答案

您对该函数的调用是错误的。 char * 在函数调用之前没有任何作用,仅在函数声明中需要它。

正确函数声明的示例:

char * getLine(char *, int, int);

正确的函数调用示例:

getLine(&line, &buff, stdin);

顺便说一句,我认为缓冲区的大小是你可以选择的,通过为第二个参数设置一个值。

关于c - 尝试在 C 中使用 getLine() 读取 stdin 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43947799/

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