函数实现:
MEMSET(3) Linux Programmer's Manual MEMSET(3)
NAME
memset - fill memory with a constant byte
SYNOPSIS
#include <string.h>
void *memset(void *s, int c, size_t n);
DESCRIPTION
The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c.
RETURN VALUE
The memset() function returns a pointer to the memory area s.
CONFORMING TO
SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
SEE ALSO
bzero(3), swab(3), wmemset(3)
memset()函数实现:
0.函数原型:
#include <string.h>
void *memset(void *s, int c, size_t n);
1.参数:
1.s:目标填充内存。
2.c:欲填充字符’c’。
3.n:指定内存前n个字节。
2.返回值:
返回指向s指针
3.功能描述:
memset函数将s指针指向的内存区的前n个字节填充为c所标示的字符。
4.实现:
void *my_memset(void *s, int c, size_t n)
{
char *s_func = (char *)s;
if(NULL == s_func || 0 > n){
return NULL;
}
while(n--){
*s_func++ = c;
}
return s;
}
=============文章结束==============
小菜总结,如有不当,欢迎批评!