use calloc(), it will initialize the memory to 0.

also always check the return value of a call to malloc/calloc/realloc.  If it is NULL then it means that the allocation failed, e.g. no memory available.