69,382
社区成员
发帖
与我相关
我的任务
分享
struct stTest1
{
char *szUserid;
char *szUserName;
};
struct stTest2
{
struct stTest1 **pTest;
};
int main()
{
struct stTest2 stTmp;
stTmp.pTest = (struct stTest1**)malloc(100);
strcpy(stTmp.pTest[0]->szUserid,"001");
}
#include<iostream>
using namespace std;
struct stTest1
{
char *szUserid;
char *szUserName;
};
struct stTest2
{
struct stTest1 **pTest;
};
int main()
{
struct stTest2 stTmp;
stTmp.pTest = (struct stTest1**)malloc(100*sizeof(struct stTest1*));
for(int i=0;i<100;++i){
stTmp.pTest[i] = (struct stTest1*)malloc(sizeof(struct stTest1));
stTmp.pTest[i]->szUserid = NULL;//此处仍需分配内存才能使用
}
return 0;
}