I need copy defined parts from input.txt file to new output.txt file.
These parts started with text-string "start" and finished with text-string "stop".
Eg. input.txt file:
123
789
start
ab 1
bc 2
ab 4
yy 5
ab 5
stop
001 some text...
354
start
ab A
ln #
ab B
stop
qwerty
m 021
Output.txt file:
I found only parts of solution:
Variables: line = line-string, fr = input.txt, fw = output.txt, ab = "ab ", start = "start", stop = "stop" :
Code:
while (fgets(line, 80, fr) != NULL) /*write each line of input.txt to variable "line" until EOF*/
if (strstr(line, start) != NULL) /*find start-string, but "if" is wrong!*/
if (strncmp(line, ab, 3) == 0) putc(line[2],fw); /*write 3rd charecters from line to output.txt*/
Could you help me, please how can I read strings from input.txt only between strings start and stop?
I think that it can be possible to use another while-loop but I am not yet successful.
Thank you.