C语言 警告:内置函数“printf”的隐式声明不兼容 [默认启用]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20041100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:19:46  来源:igfitidea点击:

warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]

csystem-calls

提问by Kara

I'm using the following C code:

我正在使用以下 C 代码:

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>

int main()
{
    int file=0;
    if((file=open("testfile.txt",O_RDONLY)) < -1)
            return 1;
    char buffer[19];
    if(read(file,buffer,19) != 19)  return 1;
    printf("%s\n",buffer);

    if(lseek(file,10,SEEK_SET) < 0) return 1;

    if(read(file,buffer,19) != 19)  return 1;
    printf("%s\n",buffer);
    return 0;
}

After compiling it produces a warning:

编译后会产生警告:

warning: incompatible implicit declaration of built-in 
function ‘printf' [enabled by default]

What does it mean and how do I appease the C compiler to not raise the warning?

这是什么意思,我如何安抚 C 编译器不发出警告?

回答by Kara

You need to add #include <stdio.h>to the top of your file.

您需要添加#include <stdio.h>到文件的顶部。