A question about how to locate a character pointer

Source: Internet
Author: User
For more information about how to locate a character pointer, see. & Lt ;? Php?handlefopen (many.txt, r); read 1st rows first. after reading, the pointer is in the last row $ bufferfgets ($ handle, 1024); read 1st rows of content echo & nbsp; $ buffer & nbsp ;. & l a question about how to locate a character pointer.
 $ Handle = fopen ("many.txt", "r ");
// Read 1st rows first. after reading, the pointer is in the last row.
$ Buffer = fgets ($ handle, 1024); // Read 1st rows of content
Echo $ buffer ."
";
// Move the pointer 5 bytes backward
Echo ftell ($ handle )."
";
Fseek ($ handle, 6, seek_cup); // The pointer moves 6 bytes backward.
// Read a row
$ Buffer = fgets ($ handle, 1024); // read the content of the second row.
Echo $ buffer ."
";
// Return the pointer to the start of the file and re-read the 1st rows because the absolute position is 0.
Fseek ($ handle, 0 );
// Read a row of data. because the pointer returns to the beginning of the file, 1st rows of data will be read.
$ Buffer = fgets ($ handle, 1024); // Read 1st lines of text
Echo $ buffer ."
"; // Output read content
Fclose ($ handle); // close the file
?>


After the program reads the file by row for the first time, the file pointer should be at the end of the first line. If you move the pointer back, it should be in the second line. Why does the program result show that the file pointer is moved to the second position in the first line, which is equivalent to moving the pointer from the beginning. However, the function parameter clearly moves six positions from the current position.

Here comes the second line of many.txt that I can play at will, because only the first line of the program results are used.
Name: zhang san, age 15, Gender: Male
Llllllllllllllllllllllllllllll

Buffer fseek


------ Solution --------------------
SEEK_CUR
And should be capitalized
------ Solution --------------------
Yes SEEK_CUR
Instead of seek_cup

Seek_cup can only be 0 when blocking errors
That is, SEEK_SET.

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.