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

  1. /***
  2. *wcsncpy.c - copy at most n characters of wide-character string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines wcsncpy() - copy at most n characters of wchar_t string
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *wchar_t *wcsncpy(dest, source, count) - copy at most n wide characters
  17. *
  18. *Purpose:
  19. *       Copies count characters from the source string to the
  20. *       destination.  If count is less than the length of source,
  21. *       NO NULL CHARACTER is put onto the end of the copied string.
  22. *       If count is greater than the length of sources, dest is padded
  23. *       with null characters to length count (wide-characters).
  24. *
  25. *
  26. *Entry:
  27. *       wchar_t *dest - pointer to destination
  28. *       wchar_t *source - source string for copy
  29. *       size_t count - max number of characters to copy
  30. *
  31. *Exit:
  32. *       returns dest
  33. *
  34. *Exceptions:
  35. *
  36. *******************************************************************************/
  37.  
  38. wchar_t * __cdecl wcsncpy (
  39.         wchar_t * dest,
  40.         const wchar_t * source,
  41.         size_t count
  42.         )
  43. {
  44.         wchar_t *start = dest;
  45.  
  46.         while (count && (*dest++ = *source++))    /* copy string */
  47.                 count--;
  48.  
  49.         if (count)                              /* pad out with zeroes */
  50.                 while (--count)
  51.                         *dest++ = L'\0';
  52.  
  53.         return(start);
  54. }
  55.  
  56.