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

  1.  /* The strncmp() function. */
  2.  
  3.  #include <stdio.h>
  4.  #include <string.h>
  5.  
  6.  char str1[] = "The first string.";
  7.  char str2[] = "The second string.";
  8.  
  9.  main()
  10.  {
  11.      size_t n, x;
  12.  
  13.      puts(str1);
  14.      puts(str2);
  15.  
  16.      while (1)
  17.      {
  18.          puts("\n\nEnter number of characters to compare, 0 to exit.");
  19.          scanf("%d", &n);
  20.  
  21.          if (n <= 0)
  22.              break;
  23.  
  24.          x = strncmp(str1, str2, n);
  25.  
  26.          printf("\nComparing %d characters, strncmp() returns %d.",
  27.                  n, x);
  28.      }
  29.  }
  30.