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

  1. /***
  2. *wcscmp.c - routine to compare two wchar_t strings (for equal, less, or greater)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Compares two wide-character strings, determining their lexical order.
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *wcscmp - compare two wchar_t strings,
  17. *        returning less than, equal to, or greater than
  18. *
  19. *Purpose:
  20. *       wcscmp compares two wide-character strings and returns an integer
  21. *       to indicate whether the first is less than the second, the two are
  22. *       equal, or whether the first is greater than the second.
  23. *
  24. *       Comparison is done wchar_t by wchar_t on an UNSIGNED basis, which is to
  25. *       say that Null wchar_t(0) is less than any other character.
  26. *
  27. *Entry:
  28. *       const wchar_t * src - string for left-hand side of comparison
  29. *       const wchar_t * dst - string for right-hand side of comparison
  30. *
  31. *Exit:
  32. *       returns -1 if src <  dst
  33. *       returns  0 if src == dst
  34. *       returns +1 if src >  dst
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. int __cdecl wcscmp (
  41.         const wchar_t * src,
  42.         const wchar_t * dst
  43.         )
  44. {
  45.         int ret = 0 ;
  46.  
  47.         while( ! (ret = (int)(*src - *dst)) && *dst)
  48.                 ++src, ++dst;
  49.  
  50.         if ( ret < 0 )
  51.                 ret = -1 ;
  52.         else if ( ret > 0 )
  53.                 ret = 1 ;
  54.  
  55.         return( ret );
  56. }
  57.  
  58.