home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch5 / strtst.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  815b  |  35 lines

  1. /*                strtst.c
  2.  *
  3.  *   Synopsis  - Calls strstr() twice to find 
  4.  *               substrings in "how now brown cow".
  5.  *               One should be found, the other is
  6.  *               nonexistent.
  7.  *
  8.  *   Objective - To provide a test program for 
  9.  *               personal version of strstr().
  10.  */
  11.     
  12. /* Include Files */
  13. #include <stdio.h>
  14. #include <string.h>
  15.     
  16. int main( void )
  17. {
  18.      char string[] = "How now brown cow";
  19.      char *substring;
  20.     
  21.      substring = strstr( string, "own" );
  22.      if ( substring == NULL )
  23.           printf( "Not found.\n" );
  24.      else
  25.           printf( "%s\n", substring );
  26.  
  27.      substring = strstr( string, "red" );
  28.      if ( substring == NULL )
  29.           printf( "Not found.\n" );
  30.      else
  31.           printf( "%s\n", substring );
  32.      return 0;
  33. }
  34.  
  35.