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

user3000926 picture user3000926 · Nov 18, 2013 · Viewed 79k times · Source

I'm using the following C code:

#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?

Answer

Kara picture Kara · Nov 18, 2013

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