memset() — Set Bytes to Value
Format
#include <string.h>
void *memset(void *dest, int c, size_t count);
Language Level
ANSI
Threadsafe
Yes
Description
The memset()
function
sets the first count bytes of dest to
the value c. The value of c is
converted to an unsigned character.
Return Value
The memset()
function
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);
}
/******************* Output should be similar to: ***************
Buffer contents: AAAAAAAAAA
Buffer contents: AAAAAAAAAABBBBBBBBBB
*/