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

  1. /***
  2. *wcsncat.c - append n chars of string to new string
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines wcsncat() - appends n characters of string onto
  8. *       end of other string
  9. *
  10. *******************************************************************************/
  11.  
  12.  
  13. #include <cruntime.h>
  14. #include <string.h>
  15.  
  16. /***
  17. *wchar_t *wcsncat(front, back, count) - append count chars of back onto front
  18. *
  19. *Purpose:
  20. *       Appends at most count characters of the string back onto the
  21. *       end of front, and ALWAYS terminates with a null character.
  22. *       If count is greater than the length of back, the length of back
  23. *       is used instead.  (Unlike wcsncpy, this routine does not pad out
  24. *       to count characters).
  25. *
  26. *Entry:
  27. *       wchar_t *front - string to append onto
  28. *       wchar_t *back - string to append
  29. *       size_t count - count of max characters to append
  30. *
  31. *Exit:
  32. *       returns a pointer to string appended onto (front).
  33. *
  34. *Uses:
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. wchar_t * __cdecl wcsncat (
  41.         wchar_t * front,
  42.         const wchar_t * back,
  43.         size_t count
  44.         )
  45. {
  46.         wchar_t *start = front;
  47.  
  48.         while (*front++)
  49.                 ;
  50.         front--;
  51.  
  52.         while (count--)
  53.                 if (!(*front++ = *back++))
  54.                         return(start);
  55.  
  56.         *front = L'\0';
  57.         return(start);
  58. }
  59.  
  60.