Use memset function to initialize a string
Syntax
C memset function has the following syntax.
void *memset(void *buf, int ch, size_t count);
Header
C memset function
is from header file string.h
.
Description
C memset function copies ch into the
first count characters of *buf
and
returns buf
.
The most common use of memset()
is to
initialize a region of memory to some value.
Example
Use C memset function to initialize a string.
#include <string.h>
#include <stdio.h>
/*from www . j a va 2 s. co m*/
int main(void){
char buf[100];
memset(buf, '\0', 100);
memset(buf, 'X', 10);
printf(buf);
}
The code above generates the following result.