[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Composition to search external text files (Pascal version available)


char *search( pat, text ) char *pat, *text; { char *p; if( *pat == EOS ) return( text ); for( p=pat; *text != EOS; text++ ) { if( *text != *p ) { text -= (p-pat); p = pat; } else if( *(++p) == EOS ) return( text - (p-pat) + 1 ); } return( NULL ); }

C source (711.srch.c) Pascal source (711.srch.p)



© Addison-Wesley Publishing Co. Inc.