memset, wmemset

指定した文字にバッファーを設定します。

構文

void *memset(
   void *dest,
   int c,
   size_t count
);
wchar_t *wmemset(
   wchar_t *dest,
   wchar_t c,
   size_t count
);

パラメーター

dest
ターゲットへのポインター。

c
設定する文字。

count
文字数。

戻り値

dest の値。

解説

dest の最初の count 文字を文字 c に設定します。

セキュリティに関するメモ 設定するバッファーに count 文字以上の空きがあることを確認してください。 詳細については、「バッファー オーバーランの回避」を参照してください

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

ルーチンによって返される値 必須ヘッダー
memset <memory.h> または <string.h>
wmemset <wchar.h>

互換性の詳細については、「 Compatibility」を参照してください。

ライブラリ

C ランタイム ライブラリのすべてのバージョン。

// crt_memset.c
/* This program uses memset to
* set the first four chars of buffer to "*".
*/

#include <memory.h>
#include <stdio.h>

int main( void )
{
   char buffer[] = "This is a test of the memset function";

   printf( "Before: %s\n", buffer );
   memset( buffer, '*', 4 );
   printf( "After:  %s\n", buffer );
}

この例では、次の出力が生成されます:

Before: This is a test of the memset function
After:  **** is a test of the memset function

wmemset の使用例を次に示します。

// crt_wmemset.c
/* This program uses memset to
* set the first four chars of buffer to "*".
*/

#include <wchar.h>
#include <stdio.h>

int main( void )
{
   wchar_t buffer[] = L"This is a test of the wmemset function";

   wprintf( L"Before: %s\n", buffer );
   wmemset( buffer, L'*', 4 );
   wprintf( L"After:  %s\n", buffer );
}

この例では、次の出力が生成されます:

Before: This is a test of the wmemset function
After:  **** is a test of the wmemset function

関連項目

バッファー操作
_memccpy
memchr, wmemchr
memcmp, wmemcmp
memcpy, wmemcpy
_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l