将内存中的一段空间设定一个值。返回这段内存区的指针。
一般用于对内存的初始化。如:
struct sample *p = malloc(sizeof(struct sample));
memset(p, 0, sizeof(struct sample));
void *memset (void *s, int c, register size_t n)
{
register unsigned char val = (unsigned char) c;
register unsigned char *ptr = (unsigned char*) s;
register unsigned char *end = ptr + n;
while (ptr < end)
*ptr++ = val;
return (s);
}
一般用于对内存的初始化。如:
struct sample *p = malloc(sizeof(struct sample));
memset(p, 0, sizeof(struct sample));
void *memset (void *s, int c, register size_t n)
{
register unsigned char val = (unsigned char) c;
register unsigned char *ptr = (unsigned char*) s;
register unsigned char *end = ptr + n;
while (ptr < end)
*ptr++ = val;
return (s);
}