首先附上我的代码
#include<stdio.h>
#include <stdlib.h>
#define ERROR 500
#define OK 200
typedef struct leader{
int length;
struct node * start;
int firstIndex;
}head;
typedef struct node{
int data;
struct node * next;
}body;
int main(){
head * Init_linklist();
int Set_linklist(head * h,int data);
void Get_linklist(head * h);
void Insert_linklist(head * h,int index,int data);
void Delete_linklist(head * h);
void Clear_linklist(head * h);
void Destory(head * h);
head * h = Init_linklist();
Set_linklist(h,1);
Set_linklist(h,2);
Set_linklist(h,3);
Set_linklist(h,4);
Set_linklist(h,5);
body *current = h->start; // 初始化一个新的临时指针
while (current) { // 当当前节点不为空时
printf("%d\t", current->data);
current = current->next; // 移到下一个节点
}
return OK;
}
body * dummy;
head * Init_linklist(){
head * h = (head *)malloc(sizeof(head));
dummy = (body *)malloc(sizeof(body));
memset(h,0,sizeof(head));
memset(dummy,0,sizeof(body));
h->start = dummy;
h->firstIndex=h->start;
return h;
}
int Set_linklist(head * h,int data){
if(h == NULL ){
printf("set error with l NULL in line 36!\n");
return ERROR;
}
struct node * n = NULL;
n = (body*)malloc(sizeof(body));
memset(n,0,sizeof(body));
n->data = data;
dummy->next = n;
dummy = n;
h->length++;
return OK;
}
我的问题
C语言指针给我指麻了