C语言(结构体和链表问题)

#include<stdio.h>structbookdata*Link(data){structbookdata*head,*p1,*p2;inti=2;for(hea... #include<stdio.h>
struct bookdata *Link(data)
{
struct bookdata *head,*p1,*p2;
int i=2;
for(head=data,p1=head,p2=&data[1];p2!=NULL;i++)
{
p1->next=p2;
p1=p2;
p2=&data[i];
}
p1->next=NULL;
return head;
}
我已经定义了机构体数组data,我想将data里的东西连成链表。。
可是出现“subscript requires array or pointer type”
不知道怎么办!!!
while(data[n].isbn!=0)
{
n++;
if(q==1)//输入第一个数据
printf("Please input the data of the book! END with \"end\"!\n");
else
printf("请输入书的数据,以输入“end”为结束!\n");
putchar('\n');
if(q==1)
printf("Please input ISBN number of the book:");
else
printf("请输入书的ISBN号:");
scanf("%s",data[n].isbn);
getchar();
if(q==1)
printf("Please input the name of book:");
else
printf("请输入书的名字:");
scanf("%s",data[n].name);
getchar();
if(q==1)
printf("Please input the price of the book:");
else
printf("请输入书的价格:");
scanf("%f",&data[n].price);
getchar();
}
Link(data,n);
fpwrite(head);
}
帮忙找找哪里错了。。。我无法输入多个数据啊。。急急急急急急急急急急急急
展开
 我来答
百度网友d050c1b
2010-05-01 · TA获得超过933个赞
知道小有建树答主
回答量:1083
采纳率:50%
帮助的人:1012万
展开全部
这个函数最好把数组的长度作为参数传进来。
看看这个能不能满足你的要求

#include <stdio.h>
struct bookdata *Link(struct bookdata data[], int data_len)
{
int i;
for (i = 0; i < data_len; i++)
data[i].next = data + i + 1;
data[data_len].next = NULL; /* 最后一个指向null */
return data;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式