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

  1. /***
  2. *strnset.c - set first n characters to single character
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _strnset() - sets at most the first n characters of a string
  8. *       to a given character.
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *char *_strnset(string, val, count) - set at most count characters to val
  17. *
  18. *Purpose:
  19. *       Sets the first count characters of string the character value.
  20. *       If the length of string is less than count, the length of
  21. *       string is used in place of n.
  22. *
  23. *Entry:
  24. *       char *string - string to set characters in
  25. *       char val - character to fill with
  26. *       unsigned count - count of characters to fill
  27. *
  28. *Exit:
  29. *       returns string, now filled with count copies of val.
  30. *
  31. *Exceptions:
  32. *
  33. *******************************************************************************/
  34.  
  35. char * __cdecl _strnset (
  36.         char * string,
  37.         int val,
  38.         size_t count
  39.         )
  40. {
  41.         char *start = string;
  42.  
  43.         while (count-- && *string)
  44.                 *string++ = (char)val;
  45.  
  46.         return(start);
  47. }
  48.