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

  1.  /* Searching with strcspn(). */
  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 = strcspn(buf1, buf2);
  21.  
  22.      if ( loc ==  strlen(buf1) )
  23.          printf("No match was found.");
  24.      else
  25.          printf("The first match was found at position %d.", loc);
  26.  }
  27.