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

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