0

I was trying to read a file using pread(), but I got "Implicit declaration of function 'pread' is invalid in C99". Is there any way to handle this?

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char **argv) 
{
        char dst[20];
        int file = open("file.txt", O_RDONLY);
        int read_res = pread(file, dst, 10, 3);
        close(file);
        return 0;
}

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Justin
  • 1
  • 1
  • 1
    Tip: When you get an error you don't understand the very first thing to do is just to paste the entire error into a search engine and hit enter. – kaylum Jan 25 '21 at 03:14
  • If you read e.g. [the Linux manual page for `pread`](https://man7.org/linux/man-pages/man2/pread.2.html) and check the "Feature Test Macro Requirements", do your code fulfill them? – Some programmer dude Jan 25 '21 at 03:17
  • Are you using `-std=c99`? Don't do that. Use `-std=gnu99` instead. – zwol Jan 25 '21 at 03:51

0 Answers0