memsetwmemset

将缓冲区设置为指定的字符。

语法

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>

有关兼容性的详细信息,请参阅 兼容性

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
memchrwmemchr
memcmpwmemcmp
memcpywmemcpy
_strnset_strnset_l_wcsnset_wcsnset_l_mbsnset_mbsnset_l