文件读取出现问题
#include <stdio.h>
#include <stdlib.h>
///虚拟头节点哦
struct unknown
{
char letter;
int index;
struct unknown*next;
};
struct item
{
float coe;
struct unknown *weizhi;
struct item*next;
};
struct item* poly_creat(FILE*fp)
{
int alllen;
fscanf(fp,"%d",&alllen);
struct item *head,*node,*end;
head=(struct item*)malloc(sizeof(struct item));
end=head;
for(int i=0;i<alllen;i++)
{
node=(struct item*)malloc(sizeof(struct item));
fscanf(fp,"%f",&node->coe);
char le;
int ind;
struct unknown *uend,*unode;
node->weizhi=(struct unknown*)malloc(sizeof(struct unknown));
uend=node->weizhi;
while(fscanf(fp,"%c%d",&le,&ind)==2)
{
printf("good\n");
unode=(struct unknown*)malloc(sizeof(struct unknown));
unode->letter=le;
unode->index=ind;
uend->next=unode;
uend=unode;
}
uend->next=NULL;
printf("%f\n",node->coe);
end->next=node;
end=node;
}
end->next=NULL;
return head;
}
void show(struct item*p)
{
while(p!=NULL)
{
printf("%f\n",p->coe);
p=p->next;
}
}
int main()
{
FILE*fp1,*fp2;
fp1=fopen("p1.txt","r");
fp2=fopen("p2.txt","r");
struct item *p1,*p2;
p1=poly_creat(fp1);
///p2=poly_creat(fp2);
show(p1->next);
return 0;
}
文件一直读不进去
这是p1.txt中的数据三代表共有一个多项式中有三个数据项,gg是判断结束符
3
10x2y3z6gg
3x2y6z7gg
12x2y3z8gg