#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
typedef struct LIST
{
int data; /* 具体的なデータ */
LIST* next; /* 次の要素へのポインタ */
}LIST;
LIST header;//ダミーヘッド
void add (void) //リスト作成
{
LIST *newcell,*p,*q;
header.next=NULL;
newcell = (LIST *)malloc(sizeof( LIST));
if( newcell == NULL )
{
puts( "メモリ不足" );
return;
}
newcell->data =rand()%100;
newcell->next =NULL;
p = &header;
while(p!=NULL)
{
p=p->next;
}
p->next=newcell;
}
void show()//表示関数
{
LIST *p;
p=&header;
while(p!=NULL){
printf("%d\n",p->data);
p=p->next;
}
}
int main(void)
{
srand((int) time(NULL));
int *p=(int*)malloc(sizeof(LIST));
int i;
for(i=0;i<100;i++)
add();
show();
}
どのあたりが間違っているのでしょうか?
教えてください。