【问题标题】:Implicit declaration of getline in C在 C 中隐式声明 getline
【发布时间】:2021-06-17 03:58:52
【问题描述】:

我最近开始学习 I/O。但是我的编译器没有执行这段代码。它显示函数的隐式声明getline。有人可以告诉我如何解决它吗?

#include <stdio.h>
#include <stdlib.h>
int main()

{
    size_t size = 10;
    char *string;
    string = (char *)malloc(size);
    getline(&string, &size, stdin);
    puts("You entered the following string: ");
    puts(string);
    return 0;
}

【问题讨论】:

标签: c io


【解决方案1】:

getline不是c语言的标准函数,在windows上不可用。

如果您使用的是 linux,请尝试检查 warning: implicit declaration of function 'getline'。

我建议你使用fgets 替代。

【讨论】:

  • 但是这段代码在我的另一台电脑上运行,它也有窗口。所以我不认为这个错误是由于操作系统造成的。
  • @PiyushJaswal 这很奇怪......我会说显示错误是正常的,在 Windows 上工作是奇怪的行为。
猜你喜欢
  • 1970-01-01
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-29
  • 2016-08-10
相关资源
最近更新 更多