#include<malloc.h>
#include<stdio.h>
typedef?struct?sys{
int?size;
int?musem;
struct?sys?*next;
}node;
node?*create(){
node?*head,*p,*r;
int?x,y;
head=r=(node?*)malloc(sizeof(node));
printf("please?input?the?num!");
scanf("%d",&x);
r.musem=x;
r.size=1;
while(y!=0){
p=(node?*)malloc(sizeof(node));
scnaf("%d",&y);
p.musem=y;
p.size=r.size+1;
r.next=p;
r=p;
}
r.next=NULL;
return?*head;
}
main(){
node?*head,*p;
char?a;
int?c,i;
head=create();
printf("println?all?the?num[y/n]?\n");
p=head;
scanf("%c",&a);
if(a=="y")
{
while(p){
println("size?is%d\n;musem?is%d\n",p.size,p.musem);
???????p=p.next;
}
}
else
{
printf("please?input?the?num!\n");
scanf("%d",&c);
for(i=0;i<c;i++){
if(i==c){
p=p.next;
}
else
printf("size?is?%d\n,musem?is?%d\n",p.size,p.musem);
}
}
}這是編譯的報(bào)錯(cuò),我為了方便就在windows上安裝了個(gè)gcc編譯器,每次寫(xiě)的線性表都會(huì)出錯(cuò),這是線性表的鏈表拜托哪位高手幫我解答一下
1 回答
已采納

onemoo
TA貢獻(xiàn)883條經(jīng)驗(yàn) 獲得超454個(gè)贊
好多錯(cuò)誤......其實(shí)報(bào)錯(cuò)中都提示了:
14 15 19 20 21 24 38行: 你定義p r為指針,訪問(wèn)指針?biāo)笇?duì)象的成員用 -> ,而不是 .(dot)
18行: scanf拼錯(cuò)了
25行: head是指針, *head解引用為node對(duì)象了,而函數(shù)要求的返回值類型就應(yīng)該是指針。將head直接返回即可。
35行: a是char型,而"y"是字符串,字符和字符串無(wú)法比較,應(yīng)該使用單引號(hào)來(lái)表示字符 'y'
- 1 回答
- 0 關(guān)注
- 1771 瀏覽
添加回答
舉報(bào)
0/150
提交
取消