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

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