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

时间:2021-10-30 06:58:35

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编译器不发出警告?

1 个解决方案

#1


72  

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

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

#1


72  

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

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