--- In [email protected], pushkar raj <[EMAIL PROTECTED]> wrote:
>
> Hi everybody,
> 
> I have two text files. One of them contains a sequence of
> character terminated by newline. File 1 for eg.....
>              gnlase#5678940
>              gnlase#3421667
>               ..................... and so on.
> 
> The other file also contains a sequence of character which
> may begin with above string. After each sequence there is
> sequence of character which describes the above string.
> File 2 for eg........
>   >gnlase#5647120
>   a sequence of character which describes above string.
>   >gnlase#543271
>   a sequence of character describing above string.
>   >...... and so on.
> I need to find the match the string pattern from file 1
> with string pattern of file 2, if they are same then i
> need to copy the description of that string in another
> file say File 3.
> 
> Each string pattern in file 2 begins with a '>' character
> which is followed by description which runs in several lines.
> Please suggest a solution to this problem using C code.

One approach (it's really bad, I just want to show the principle) goes
like this:
1) open file 1 for reading.
2) open file 3 for writing.
3) while not eof( file 1) reached, repeat:
3a) read line from file 1.
3b) print to a char[] variable: ">" + string.
3c) open file 2 for reading.
3d) while not eof( file 2) reached, repeat:
3d1) read line from file 2.
3d2) if line equals char[] variable, then:
3d2a) read next line from file 2.
3d2b) write this line to file 3.
3d2c) leave this loop (3d).
3d3) continue with next line from file 2.
3e) close file 2.
4) close file 3.
5) close file 1.

Why it's so bad? Consider that both file 1 and file 2 consist of
several 100,000 lines; then the inner loop will (on the average) be
executed 5 billions times. An utter performace nightmare.

But the principle is valid and can be used in any programming language
allowing direct text file access and supporting loops which can be
left in the middle of the processing of its body.

Regards,
Nico

Reply via email to