50

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?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
  • 31
    `#include ` – Yu Hao Nov 18 '13 at 06:00
  • 6
    possible duplicate of [c - warning: implicit declaration of function ‘printf’](http://stackoverflow.com/questions/14069226/c-warning-implicit-declaration-of-function-printf) – Kara Nov 18 '13 at 06:03

1 Answers1

105

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

Kara
  • 6,115
  • 16
  • 50
  • 57
  • 5
    @rkioji because the compiler makes guess about the definition of a function and it makes good guess about the function present in stdio.h – Rahul Jun 02 '19 at 06:02