Syntax
#include <string.h> /* also in <memory.h> */ void *memset(void *dest, int c, size_t count);Description
memset sets the first count bytes of dest to the value c. The value of c is converted to an unsigned char.
memset returns a pointer to dest.
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 = 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 ****************************************************************************/ }
Related Information