Format
#include <string.h> /* also in <memory.h> */ void *memset(void *dest, int c, size_t count);
Language Level: ANSI, XPG4, Extension
memset sets the first count bytes of dest to the value
c. The value of c is converted to an
unsigned character.
Return Value
memset returns a pointer to dest.
Example
This example sets 10 bytes of the buffer to A and the
next 10 bytes to B.
#include <string.h> #include <stdio.h>
#define BUF_SIZE 20
int main(void)
{
char buffer[BUF_SIZE + 1];
char *string;
memset(buffer, 0, sizeof(buffer));
string = (char *) memset(buffer,'A', 10);
printf("\nBuffer contents: %s\n", string);
memset(buffer+10, 'B', 10);
printf("\nBuffer contents: %s\n", buffer);
return 0;
/*********************************************
The output should be:
Buffer contents: AAAAAAAAAA
Buffer contents: AAAAAAAAAABBBBBBBBBB
*********************************************/
}
![]()
memccpy -- Copy Bytes
memchr -- Search Buffer
memcmp -- Compare Buffers
memcpy -- Copy Bytes
memicmp -- Compare Bytes
memmove -- Copy Bytes
strnset - strset -- Set Characters in
String
<memory.h>
<string.h>