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

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