This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>. All rights reserved. Released under the GNU General Public License.
![]() |
![]() |
![]() |
![]() |
#include <string.h> void *memset(void *dest, int c, size_t n);
n
bytes of the specified buffer dest
with the
specified character c
. Returns the dest
parameter.
char buf[9]; memset(buf + 2, 'x', 5);this is the state of the
buf
array before and after the
call of memset
(? means
any character):
#include <string.h> void *memset(void *dest, int c, size_t n) { unsigned char *dp = dest; while (n-- > 0) *dp++ = c; return dest; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char buf[8]; memset(buf, 'x', 7); memset(buf + 1, 'y', 5); buf[7] = '\0'; /* Add the terminating null. */ printf("%s\n", buf); /* Prints "xyyyyyx". */ return EXIT_SUCCESS; }