home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list1712.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-16  |  513 b   |  26 lines

  1.  /* Searching with strstr(). */
  2.  
  3.  #include <stdio.h>
  4.  #include <string.h>
  5.  
  6.  main()
  7.  {
  8.      char *loc, buf1[80], buf2[80];
  9.  
  10.      /* Input the strings. */
  11.  
  12.      printf("Enter the string to be searched: ");
  13.      gets(buf1);
  14.      printf("Enter the target string: ");
  15.      gets(buf2);
  16.  
  17.      /* Perform the search. */
  18.  
  19.      loc = strstr(buf1, buf2);
  20.  
  21.      if ( loc ==  NULL )
  22.          printf("No match was found.");
  23.      else
  24.          printf("%s was found at position %d.", buf2, loc-buf1);
  25.  }
  26.