Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

c - Extract lines containing a string from a file into another file without using strstr

So if input.txt is:

abd123
123gy
dhakf
hu123

and target string is "123"

I need the result.txt to be:

abd123
123gy
hu123

I would use something like

while(fscanf(fp1, target, ...) != 0)
      fputs(target, fp2);

I have to do this without using functions of string.h.

question from:https://stackoverflow.com/questions/65840293/extract-lines-containing-a-string-from-a-file-into-another-file-without-using-st

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would use getline to read every line of the file and use strstr to check if it contains the line that you are looking for. That should be enough to go off, good luck :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...