I am reading a file with fgetc, so each time it reads a character, the cursor positio gets changed.
Is it possible to know, after each read, the "coordinates" of the cursor on the file in terms of column and line number?
Thanks
The ftell() function in C++ returns the current position of the file pointer.
1 systems, the file position is simply an integer representing the number of bytes from the beginning of the file. The file position is normally set to the beginning of the file when it is opened, and each time a character is read or written, the file position is incremented.
SEEK_CUR: It indicates the current position of the pointer of the file. SEEK_END: As the name indicates, it moves the pointer of the file to the end of the file. SEEK_SET: As the name indicates, it moves the file pointer to the beginning of the start of the file.
The fseek() function seeks in an open file. This function moves the file pointer from its current position to a new position, forward or backward, specified by the number of bytes. Tip: You can find the current position by using ftell()!
You can use ftell
It does not give you the position in terms of row and column but gives the current position in the stream from the start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With