问个c语言链表的问题???

不知道我这个链表哪里建立错了,每次编译都通不过。
我觉得原理应该搞懂了,求大神指点一下啊 啊啊啊啊

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
typedef struct link
{
    int a;
    struct link *next;
}ST;
ST *begain;
ST *p;
void creat()
{
    ST *h;
    srand((unsigned)time(NULL));
    h->a=rand()%100+1;
    h->next=begain->next;
    begain->next=h;
}
void Lprint()
{
    int k=0;
    p=begain->next;
    do
    {   
        printf("%6d",p->a);
        k++;
        p=p->next;
    }while(p==NULL);
}
void main()
{
    begain->next=NULL;
    creat();
    Lprint();
}

有两个问题:
1.需要为每个节点都malloc一个空间
2.do()while这里的判断条件应该是p!=NULL

 #include <stdio.h>
#include <time.h>
#include <stdlib.h>
typedef struct link
{
    int a;
    struct link *next;
}ST;
ST *begain;
ST *p;
void creat()
{
    ST *h = (ST *)malloc(sizeof(ST));
    srand((unsigned)time(NULL));
    h->a=rand()%100+1;
    h->next=begain->next;
    begain->next=h;
}
void Lprint()
{
    int k=0;
    p=begain->next;
    do
    {   
        printf("%6d",p->a);
        k++;
        p=p->next;
    }while(p!=NULL);
}
void main()
{
    begain = (ST *)malloc(sizeof(ST));
    begain->next=NULL;
    creat();
    Lprint();
}

图片说明

new一个节点!我不太懂

你在create函数中,需要给指针分配存储空间
ST *begain 改为
ST *begain = (ST *)malloc(sizeof(ST));
其他的也一样,在使用指针的时候,要保证这个指针指向了一块内存空间。

这样定义感觉更好

 void ST* creatNode()
{
    ST *h = (ST *)malloc(sizeof(ST));
    srand((unsigned)time(NULL));
    h->a=rand()%100+1;
    h->next=null;
   return h;
}