结构体指针的指针的问题
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
typedef struct tagTItem
{
char Name[10];
double Amt;
} TItem;
void getmem(TItem** item)
{
int i=0;
item = (TItem**)malloc(2*sizeof(TItem*));
if (item==NULL) { printf("malloc e.\n"); return; }
for (i=0; i<2; i++) {
*(item+i) = (TItem*)malloc(sizeof(TItem));
sprintf((*(item+i))->Name, "china%d", i+1);
(*(item+i))->Amt = (i+1)*12.0;
sprintf((*(item+i))->Name, "china%d", i+1);
(*(item+i))->Amt = (i+1)*12.0;
}
}
int main(int argc, char* argv[])
{
int i = 0, n = 0;
TItem **itm = NULL;
getmem(itm);
for(i=0; i<2; i++) {
printf("[%s]\n", (*itm++)->Name);
}
free(itm);
getchar();
return 0;
}
// 不知道哪里错了,打印的时候就core dump勒,帮忙看看,指针不会用啊