Страницы

Translate

вторник, 24 декабря 2013 г.

Exercise 8.6. The standard library function calloc(n,size) returns a pointer to n objects of size size, with the storage initialized to zero

Exercise 8.6. The standard library function calloc(n,size) returns a pointer to n objects of
size size, with the storage initialized to zero. Write calloc, by calling malloc or by
modifying it.









#include <stdio.h>
#include <stdlib.h>

/* calloc */

void _calloc(unsigned n, unsigned size)
{
    unsigned i, nsize;
    char *p, *q;
   
    nsize = n * size;
    if((p = q = malloc(nsize)) != NULL)
        for(i = 0; i < nsize; i++)
            *q++=0;
    return p;
}

Комментариев нет:

Отправить комментарий