[SOLVED] how to tell fread and fwrite where to go read from or write into a file


I am learning to use fread and fwrite right now.

As far as I understand, from the documentation, it just seems to read from or write into a specified number of bytes, but always from the beginning of the file. Is there any way not to have to start at the beginning of the file or am I misunderstanding the functions?


use fseek

int fseek(FILE *pointer, long int offset, int position)
pointer: pointer to a FILE object that identifies the stream.
offset: number of bytes to offset from position
position: position from where offset is added.

zero if successful, or else it returns a non-zero value 

SEEK_END : It denotes end of the file.
SEEK_SET : It denotes starting of the file.
SEEK_CUR : It denotes file pointer’s current position.

Answered By – balu

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.