Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <string.h>
void *memset(void *dest, int c, size_t count);
The memset() built-in function sets the first count bytes of dest to the value c converted to an unsigned int.
memset() returns the value of dest.
⁄* CELEBM15
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
#define HALF_BUF_SIZE BUF_SIZE⁄2
int main(void)
{
char buffer[BUF_SIZE + 1];
char *string;
memset(buffer, 0, sizeof(buffer));
string = (char *)memset(buffer,'A', HALF_BUF_SIZE);
printf("\nBuffer contents: %s\n", string);
memset(buffer+HALF_BUF_SIZE, 'B', HALF_BUF_SIZE);
printf("\nBuffer contents: %s\n", buffer);
}
Buffer contents: AAAAAAAAAA
Buffer contents: AAAAAAAAAABBBBBBBBBB