#include
#include
#include
#define err(msg) perror(msg)
static int test_pvoid(void)
{
void *pvoid;
int i;
char **ppchar;
if ((pvoid = calloc(3, sizeof(char *))) == NULL) {
err("calloc");
goto out;
}
ppchar = pvoid;
for (i = 0; i < 3; i++) {
if ((ppchar[i] = calloc(10, sizeof(char))) == NULL) {
err("calloc");
goto err;
}
}
strncpy(ppchar[0], "aaaaa", 5);
strncpy(ppchar[1], "bbbbb", 5);
strncpy(ppchar[2], "ccccc", 5);
for (i = 0; i < 3; i++)
printf("%s\n", ppchar[i]);
for (i = 0; i < 3; i++)
free(ppchar[i]);
free(pvoid);
return 0;
err:
free(pvoid);
out:
return -1;
}
int main(void)
{
test_pvoid();
return 0;
}
阅读(980) | 评论(0) | 转发(0) |