Read a specific range of lines from a file using c

Posted by James Joy on Stack Overflow See other posts from Stack Overflow or by James Joy
Published on 2012-06-22T15:03:48Z Indexed on 2012/06/22 15:16 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

I have the following content in a file:

hhasfghgsafjgfhgfhjf
gashghfdgdfhgfhjasgfgfhsgfjdg
jfshafghgfgfhfsghfgffsjgfj
.
.
.
.
.
startread
hajshjsfhajfhjkashfjf
hasjgfhgHGASFHGSHF
hsafghfsaghgf
.
.
.
.
.
stopread
.
.
.
.
.
.
jsfjhfhjgfsjhfgjhsajhdsa
jhasjhsdabjhsagshaasgjasdhjk
jkdsdsahghjdashjsfahjfsd

I need to read the lines from the next line of startread till the previous line of stopread using a c code and store it to a string variable(of course with a \n for every line breaks). How can i achieve this? I have used fgets(line,sizeof(line),file); but it starts reading from the beginning. I don't have the exact line number to start and stop reading since the file is written by another C code. But there are these identifiers startread and stopread to identify whereto start reading. Operating platform is linux. Thanks in advance.

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux