23,124
社区成员
发帖
与我相关
我的任务
分享
/* 声明了结构体 */
typedef struct _Planmodel Planmodel;
struct _Planmodel {
const char *title;
const char *resume;
};
main(){
int nrow = 5
Planmodel *stData = (Planmodel *)malloc(sizeof(Planmodel) + nrow +1);
for(i = 0; i < nrow; i++){
stData->title = "test";
stData->resume = "test";
stData += sizeof(Planmodel);
}
free(stData);//这里出错,提示一堆错误信息。
}
main(){
int nrow = 5;
Planmodel *p;
Planmodel *stData = (Planmodel *)malloc(sizeof(Planmodel) * nrow ); // 这里好像要改
if (stData == NULL)
{ printf("..."); return 1;/* 一定要养成这个习惯,虽然大多数情况没用 */ }
p = stData;
for(i = 0; i < nrow; i++){
p->title = "test";
p->resume = "test";
p++; // 注意这里
}
free(stData);//这里出错,提示一堆错误信息。
}