Em đang học linked list bằng c thì gặp lỗi như thế này
đây là code của em ạ
#include<stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
};
typedef struct node node;
node* create(int n){
node *p = (node*)malloc(sizeof (node));
p->data = n;
p->next = NULL;
return p;
}
node *linked(int n, node *p){
node *t = create(n);
if (p->next == NULL){
p->next = t;
printf("%d\n", p->data);
}
else{
while (p->next!=NULL)
p = p->next;
p->next = t;
}
return t;
}
void in(int n, node *p){
node *t = p;
while (t != NULL){
printf("%d ", t->data);
t = t->next;
}
}
int main(){
int n, temp;
scanf("%d", &n);
node *p;
for (int i=0; i<n; ++i){
scanf("%d", &temp);
p = linked(p, temp);
}
in(n,p);
}
Em không biết nên sửa thế nào và tại sao nó lại báo lỗi, mọi người chỉ giúp em với ạ, em cảm ơn!