Skip to content
Advertisement

Invalid conversion from ‘FILE* {aka _IO_FILE*}’ to ‘int’

When trying to compile this little example…

JavaScript

…I get a compiler error regarding the call to lseek(). The output is:

JavaScript

For the record: I have also tried using both lseek(*foo, 5, SEEK_CUR); and lseek(&foo, 5, SEEK_CUR);, but that only makes things worse. (I really didn’t expect that to solve anything either.)

Referring to the man-page for lseek(3):

Synopsis
off_t lseek(int fildes, off_t offset, int whence);

Description
The lseek() function shall set the file offset for the open file description associated with the file descriptor fildes, as follows:

[……..]

I interpret this to mean that the first argument should be the file descriptor, which in this case is foo.

Q: What’s wrong here?

Advertisement

Answer

If you want to seek within file, use fseek. I never saw lseek used this way

More info: what’s the difference between `fseek`, `lseek`, `seekg`, `seekp`?

Advertisement