fseek

int fseek(FILE *stream, long offset, int whence);

Posted in c, fseek, programming on February 8th, 2010 by fseek – Be the first to comment

For a site named fseek, the first post had to be about the fseek C function.

The fseek() function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is obtained
by adding offset bytes to the position specified by whence. If whence is
set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the
start of the file, the current position indicator, or end-of-file, re-
spectively. A successful call to the fseek() function clears the end-of-
file indicator for the stream and undoes any effects of the ungetc(3)
function on the same stream.

Example: How to use fseek to set the file position to the end of a file

FILE *fp;
fp = fopen(“myfile.txt”, “r”);
if(fp)
{
fseek(fp, 0, SEEK_SET);
}

Simple and easy. About this blog? Expect a lot about C, Unix, Linux, programming and hacking in general.