#include
#include
typedef struct Node
{
int data;
struct Node* next;
}Node, *LinkList;//鏈表
void InitList(LinkList *L)
{
*L = (LinkList)malloc(sizeof(Node));
(*L)->next = NULL;
}//初始化鏈表
void CreatFromTail(LinkList L,int c)
{
Node r, *s;
r = L;
s = (Node)malloc(sizeof(Node));
s->data = c;
r->next = s;
r = s;
}//建立鏈表
int main()
{
LinkList total;
InitList(&total);
CreatFromTail(total, 1);
printf("%d", total->data);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node* next;
}Node, *LinkList;//鏈表
void InitList(LinkList *L)
{
*L = (LinkList)malloc(sizeof(Node));
(*L)->next = NULL;
}//初始化鏈表
void CreatFromTail(LinkList L,int c)
{
Node *r, *s;
r = L;
s = (Node*)malloc(sizeof(Node));
s->data = c;
r->next = s;
r = s;
}//建立鏈表
int main()
{
LinkList total;
InitList(&total);
CreatFromTail(total, 1);
printf("%d", total->next->data);
return 0;
}
你total->data事實上沒有初始化也沒有賦值,你賦值在s上,也就是total->next上