Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get file cursor position in C

Tags:

c

file

io

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

like image 614
asdf Avatar asked Dec 25 '09 09:12

asdf


People also ask

How do we get current position of file pointer?

The ftell() function in C++ returns the current position of the file pointer.

What is file position in C?

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.

What is Seek_cur in C?

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.

What is the use of fseek () function?

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()!


1 Answers

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.

like image 185
codaddict Avatar answered Oct 20 '22 20:10

codaddict