home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / msdos / c / string.arc / STRNCMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1984-12-31  |  768 b   |  24 lines

  1. /*  File   : strncmp.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 10 April 1984
  4.     Defines: strncmp()
  5.  
  6.     strncmp(s, t, n) compares the first n characters of s and t.
  7.     If they are the same in the first n characters it returns 0,
  8.     otherwise it returns the same value as strcmp(s, t) would.
  9. */
  10.  
  11. #include "strings.h"
  12.  
  13. int strncmp(s, t, n)
  14.     register char *s, *t;
  15.     register int n;
  16.     {
  17.     while (--n >= 0) {
  18.         if (*s != *t++) return s[0]-t[-1];
  19.         if (!*s++) return 0;
  20.     }
  21.     return 0;
  22.      }
  23.