0

Can I set my pointer of my file to the second line or the third line using c and if so, is it possible to do it using the rewind() function?.

hyde
  • 60,639
  • 21
  • 115
  • 176
Kkkkkk kkkkkk
  • 11
  • 1
  • 5

2 Answers2

2

From what I know, rewind will always set the pointer to the beginning of the file.

Look up fseek and fsetpos for setting a read/write position in a FILE *.

To set a position in relation to an EOL (end of line) marker, your code will have to read the data to find out when the EOL appears... (even if you use library functions, such as getline or fgets).

...So, no, you can't use seek or fsetpos for setting the position in relation to a line.

Myst
  • 18,516
  • 2
  • 45
  • 67
0

These system calls do not understand the concept of a line, which is user/application specific. So fseek() cannot do anything more than go to a particular byte offset in the file. rewind() goes to the start of the file. So there is no way to go to a line#.

Mohan
  • 33
  • 8