Fseek functions useful for reading files in C ++

Source: Internet
Author: User

Int fseek (File * stream, long offset, int origin );

The first parameter stream is the file pointer.

The second parameter offset is the offset. positive values indicate the positive offset and negative values indicate the negative offset.

The third parameter origin is used to set the offset starting from the file. The possible values include seek_cur, seek_end, and seek_set.

Seek_set: Start of the file

Seek_cur: current location

Seek_end: End of the file

Seek_set, seek_cur, and seek_end are respectively 0, 1 and 2.

In short:

Fseek (FP, 100l, 0); move the internal pointer of the file to 100 bytes away from the beginning of the file;

Fseek (FP, 100l, 1); move the internal pointer of the file to 100 bytes away from the current position of the file;

Fseek (FP,-100l, 2); returns the internal pointer of the file to the first byte from the end of the file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.