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

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