请问,我这个链表输出不了值是哪里出问题了

#include "stdio.h"
#include "stdlib.h"
typedef struct linklist
{
int num;
struct linklist *next;
}link;
int main(void)
{
link *linkhead(int n);
int n;
void print(link *p);
scanf("%d",&n);
print(linkhead(n));
return 0;
}
link *linkhead(int n)
{
int i=0;
link *temp,*new,head;
head=(link
)malloc(sizeof(link));
head->next=NULL;
while(i<=n)
{
new=(link*)malloc(sizeof(link));
new->next=0;
temp=head;
while(temp->next!=NULL)
temp=temp->next;
temp->next=new;
i++;
}
temp->next=NULL;
temp=head;
while(temp->next!=NULL)
{
scanf("%d",temp->num);
temp=temp->next;
}
printf("%d\n",temp->num);
return head;
}
void print(link *p)
{
while(p->next!=NULL)
{
printf("%d",p->num);
p=p->next;
}
}

  • ```

**
3. **

```

   scanf("%d", &temp->num);

输入的变量要用&取地址

正确代码如下:(如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮)

#include "stdio.h"
#include "stdlib.h"
typedef struct linklist
{
    int num;
    struct linklist *next;
} link;
int main(void)
{
    link *linkhead(int n);
    int n;
    void print(link * p);
    scanf("%d", &n);
    print(linkhead(n));
    return 0;
}
link *linkhead(int n)
{
    int i = 0;
    link *temp, *new, *head;
    head = (link *)malloc(sizeof(link));
    head->next = NULL;
    while (i <= n)
    {
        new = (link *)malloc(sizeof(link));
        new->next = 0;
        temp = head;
        while (temp->next != NULL)
            temp = temp->next;
        temp->next = new;
        i++;
    }
    temp->next = NULL;
    temp = head;
    while (temp->next != NULL)
    {
        scanf("%d", &temp->num);
        temp = temp->next;
    }
    return head;
}
void print(link *p)
{
    while (p->next != NULL)
    {
        printf("%d ", p->num);
        p = p->next;
    }
}

img

temp->next=NULL;这一句多余,删掉
temp=head;

scanf("%d",temp->num);这一句,改成scanf("%d",&temp->num);