じゃあ
malloc(sizeof(char *) * NUM) → calloc(NUM, sizeof(char*))
malloc(j + 1) → calloc(j+1, 1)