1樓:網友
從始至終head指標的值都是null,所以一旦引用head->next肯定coredump
c語言連結串列段錯誤
2樓:網友
能不能把錯誤提示貼出來。
c語言建立連結串列,以下**有錯誤?為什麼啊?
3樓:風若遠去何人留
pre型別不需要node **
只需要node*就好了。
修改如下。#include
#include
#include
struct node
void createlist(node** list)}void printf1(node* list)printf("");
int main()
c語言,建立單連結串列時出現問題,誰能解釋下為什麼出錯,怎麼改錯???
4樓:
你的定義有問題, linklist已經是指標型別了,你去定義linklist *p = null, *pr = head;
p和pr就成了指標的指標,所以你取裡面的next 和 data當然不對了,你改成。
linklist p = null, pr = head; 試試吧。
5樓:小智奇談
參考這個吧我寫的。
bool additem(list * add,const item * dat)
elsestatus = false;
if(*add == null)
add = current;
elsecurrent ->next = null;
strcpy(current ->dat ->title);
current ->= dat ->reting;
priv = current;
return status;}
c語言連結串列又出問題了!!
6樓:網友
#include
#include
#include
#include
struct dept {
int id;
char *name;
int balance;
struct dept *next;
typedef struct dept dept_t;
dept_t *create_dept(int dept_id, char *dept_name, int dept_balance)
dept_t *list_head,*newnode,*tailnode;
list_head =tailnode= (dept_t *)malloc(sizeof(dept_t));//建立空連結串列。
tailnode->next=null;
newnode= (dept_t *)malloc(sizeof(dept_t));//建立第乙個節點。
newnode->id = dept_id;
newnode->name = dept_name;
newnode->balance = dept_balance;
newnode->next = null;
tailnode->next=newnode;
tailnode=newnode;
return list_head;//你在這裡沒返回。
void free_dept(dept_t *dept)
dept_t * temp;
dept_t *cur=dept->next;
while(cur!= null)//這裡是判斷連結串列節點存不存在,是不管裡面的值的, //只能用位址,如果用*cur,它指向的是乙個結構體資料,會報錯。
temp=cur->next;
free(cur);
cur=temp;
dept->next = null;
int main()
int sum;
char *a;
dept_t *p;
scanf("%s %d",a,&sum);
p=create_dept(51423, a, sum);//這裡多了*,指標變數存的是位址。
free_dept(p);
**修改成這樣就ok了。
C語言fwrite 寫入連結串列錯誤
呼叫fwrite時,第乙個引數p,型別是struct books 第二個引數是sizeof struct books 型別不一樣,乙個是books,乙個是books。如果是連結串列的話,結構中的指標在回讀後一定記住要重建。c語言如何將連結串列裡的值寫入檔案 先定義乙個全域性的檔案 file fp 讀檔案。if...
c語言刪除連結串列問題,C語言刪除連結串列問題
del函式while改為 while p1 null if p1 data num p1 p1 next 這個就需要你判斷了,你首先需要將連結串列的資料全部遍歷一遍,在遍歷的同時就判斷該資料是否為你要刪除的資料,如果是,就刪除,繼續遍歷 一直到結束,這樣就可以吧1全部刪除了。滿意請採納!用這個程式到...
C語言連結串列
include include struct chain struct chain create return head struct chain inlink struct chain head,int a,int b int a代表要插入的節點,int b代表建立節點的資料域 if head v...