0
我在C中創建這個程序,linkelist從用戶處獲取輸入,只是爲了創建一個節點並將頭指向該節點並打印該節點元素的值和地址。我在運行時遇到了分段錯誤,請幫我解決問題。LinkList In C;分段錯誤
#include<stdio.h>
#include<stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* head;
void main() {
head = NULL;
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
printf("Enter the number you want in node\n");
scanf("%d",(int *)temp->data);
temp->next = NULL;
head = temp;
printf("the address of node is %p",head);
printf("the value is %d",temp->data);
}
'的scanf( 「%d」,(INT *)TEMP->數據);' - >'scanf(「%d」,&temp-> data);' – BLUEPIXY
錯誤:'>'令牌之前的預期表達式 scanf(「%d」,(int *)temp-> data); - > scanf (「%d」,&temp-> data); –
謝謝@BLUEPIXY它帶有&temp->數據,:) –