C语言链表问题不知道是哪里出问题了,我想创建3个长度的链表,不知道是打印函数出错还是创建函数出错,如何解决?

C语言链表问题
不知道是哪里出问题了,我想创建3个长度的链表,不知道是打印函数出错还是创建函数出错,运行的结果很奇怪。


#include 
#include 
 struct student
{
    char name;
    int num;
    struct student* next;
};
 struct student *setup()
{
     struct student* head;
     struct student* p1, * p2;
     head = NULL;
     p1 = p2 = (struct student*)malloc(sizeof(struct student));
     for (int i = 0; i < 3; i++)
     {
         scanf_s("%c", &p1->name);
         getchar();
         scanf_s("%d", &p1->num);
         if (head == NULL)
         {
             head = p1;
             //p2 = p1;
         }
         else
         {
             p2->next = p1;
         }
     }
     p2->next = NULL;
     return head;
}
 void print(struct student* head)
 {
     struct student* p;
     p = head;
     if (head != NULL)
     {
         while (p != NULL)
         {
             printf("%c   %d\n", p->name, p->num);
             p = p->next;
         }
     }
     else
         printf("down\n");
 }
 int main()
 {
     struct student* std;
     std = setup();
     print(std);
     
     return 0;
 }


img


struct student *setup()
{
    struct student *head;
    struct student *p1, *p2;
    head = NULL;
    // p1 = p2 = (struct student *)malloc(sizeof(struct student));
    for (int i = 0; i < 3; i++)
    {
        p1 = (struct student *)malloc(sizeof(struct student));
        fflush(stdin);
        scanf_s("%c", &p1->name);
        // getchar();
        scanf_s("%d", &p1->num);
        if (head == NULL)
        {
            head = p1;
            // p2 = p1;
        }
        else
        {
            p2->next = p1;
        }
        p2 = p1;
    }
    p2->next = NULL;
    return head;
}