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?.
Asked
Active
Viewed 3,727 times
0
-
3How are you defining what a 'line' is? Figure that out, and you'll be able to skip to anywhere in the file by counting offsets from the end-of-line markers. – Dylan LaCoursiere Mar 14 '16 at 06:11
-
`FILE*` is not a line pointer – phuclv Mar 14 '16 at 06:20
2 Answers
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