memset wmemset

將指定的字元緩衝區。

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

參數

  • 目的地
    到目的地的指標。

  • c
    若要設定的字元。

  • 計數
    字元數。

傳回值

dest 的值

備註

設定第一個count個字元的dest字元c。

安全性附註確定目的緩衝區至少具有足夠的空間count個字元。如需詳細資訊,請參閱避免緩衝區滿溢,

需求

常式

所需的標頭

memset

<memory.h> 或者 <string.h>

wmemset

<wchar.h>

其他的相容性資訊,請參閱相容性在簡介中。

文件庫

所有版本的 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 );
}

Output

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, '*', 4 );
   wprintf( L"After:  %s\n", buffer );
}

Output

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

.NET Framework 對等用法

System::Buffer::SetByte

請參閱

參考

緩衝區操作

_memccpy

memchr wmemchr

memcmp wmemcmp

memcpy wmemcpy

_strnset、 _strnset_l、 _wcsnset、 _wcsnset_l、 _mbsnset、 _mbsnset_l