Read a specific range of lines from a file using c
- by James Joy
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.