Share via


memset, wmemset

Mengatur buffer ke karakter tertentu.

Sintaks

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

Parameter

dest
Penunjuk ke tujuan.

c
Karakter yang akan diatur.

count
Jumlah karakter.

Nilai hasil

Nilai dari dest.

Keterangan

Mengatur karakter pertama count ke dest karakter c.

Catatan Keamanan Pastikan bahwa buffer tujuan memiliki ruang yang cukup untuk setidaknya count karakter. Untuk informasi selengkapnya, lihat Menghindari overruns buffer.

Secara default, status global fungsi ini dicakup ke aplikasi. Untuk mengubah perilaku ini, lihat Status global di CRT.

Persyaratan

Rutin Header yang diperlukan
memset <memory.h> atau <string.h>
wmemset <wchar.h>

Untuk informasi kompatibilitas selengkapnya, lihat Kompatibilitas.

Pustaka

Semua versi pustaka run-time C.

Contoh

// 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 );
}

Contoh menghasilkan output ini:

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

Berikut adalah contoh penggunaan 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 );
}

Contoh menghasilkan output ini:

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

Baca juga

Manipulasi buffer
_memccpy
memchr, wmemchr
memcmp, wmemcmp
memcpy, wmemcpy
_strnset, _strnset_l, _wcsnset, _wcsnset_l, _mbsnset, _mbsnset_l