fopen Open the same file multiple times

Source: Internet
Author: User
Recently in a project, need to read the Tex file, but the function of each call, open a file, after the call will find that the call will not open the file, the data is not read at all, and then take a most stupid method, each call function re-use fopen open a file, and finally really crazy, Find the information on the Internet, understand the principle. When we use a pointer to open a file, it is through the movement of the pointer to read the data inside, if you use this pointer again, you have to initialize the pointer, put the pointer to the initial position. After each use of the pointer to read the file, add a sentence behind the program

Fseek (Fp,0,seek_set);

Add this sentence, you call once fopen can read the file multiple times, but remember not to use Fclose to close the file, shut down you will not happy, must be reopened. Understand these are not very happy, do not see so many fopen, want to open several times.

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.