home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / strncmp.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  1KB  |  54 lines

  1. /***
  2. *strncmp.c - compare first n characters of two strings
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines strncmp() - compare first n characters of two strings
  8. *       for lexical order.
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *int strncmp(first, last, count) - compare first count chars of strings
  17. *
  18. *Purpose:
  19. *       Compares two strings for lexical order.  The comparison stops
  20. *       after: (1) a difference between the strings is found, (2) the end
  21. *       of the strings is reached, or (3) count characters have been
  22. *       compared.
  23. *
  24. *Entry:
  25. *       char *first, *last - strings to compare
  26. *       unsigned count - maximum number of characters to compare
  27. *
  28. *Exit:
  29. *       returns <0 if first < last
  30. *       returns  0 if first == last
  31. *       returns >0 if first > last
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36.  
  37. int __cdecl strncmp (
  38.         const char * first,
  39.         const char * last,
  40.         size_t count
  41.         )
  42. {
  43.         if (!count)
  44.                 return(0);
  45.  
  46.         while (--count && *first && *first == *last)
  47.         {
  48.                 first++;
  49.                 last++;
  50.         }
  51.  
  52.         return( *(unsigned char *)first - *(unsigned char *)last );
  53. }
  54.