標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <string.h>
void *memset(void *dest, int c, size_t count);
memset() 組み込み関数は、dest の 先頭 count バイトを、符号なし int に 変換される c の値に設定します。
memset() は、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