请指教!
#include<malloc.h>
#include<stdio.h>
struct element
{
int number;
element *point;
};
void main()
{
int i=0,j;
element *curret;
curret=(element*)(calloc(10,sizeof(element)));
if(curret)
printf("Memory Allocated at: %x",curret);//x是16进制
else
printf("Not Enough Memory!\n");
while(i<10)
{
printf("请输入数据:");
scanf("%d",&j);
curret->number=j;
i++;
curret=curret->point;
}
}
为什么这样写不行呢?这个calloc(),是分配10个大小为element的空间,也就是相当与生成了10个动态的element,头指针是curret:
while(i<10)
{
printf("请输入数据:");
scanf("%d",&j);
curret->number=j;
i++;
curret=curret->point;
}
还是说分配了10*element大小的空间,他只有1个element,用curret指向他.