|
楼主 |
发表于 2020-1-6 14:12:01
|
显示全部楼层
#include<stdio.h>
#include<stdlib.h>
struct arc_data
{
float x,y;
struct arc_data *next;
};
struct arc_type
{
int id, point;
char name[10];
struct arc_data *data;
struct arc_type *next;
};
void main()
{
FILE *fin,*fout;
struct arc_type *list,*l1,*l2;
struct arc_data *head,*p1,*p2;
fin=fopen("E:\\data.dat","rb");
if(fin==NULL)
{
printf("err");
exit(1);
}
int n1=0;
while(!feof(fin))
{
l1=(struct arc_type *)malloc(sizeof(struct arc_type));
fscanf(fin,"%d,%s%d",&l1->id,&l1->name,&l1->point);
for(int i=0,n2=0;i<l1->point;i++)
{
p1=(struct arc_data *)malloc(sizeof(struct arc_data));
fscanf(fin,"%f,%f",&p1->x,&p1->y);
n2++;
if(n2==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
p2->next=NULL;
l1->data=head;
n1++;
if(n1==1)
list=l1;
else
l2->next=l1;
l2=l1;
}
l2->next=NULL;
fclose(fin);
fout=fopen("E:\\data.dat","w+");
if(fout==NULL)
{
printf("err!");
exit(1);
}
l1=list;
while(l1!=NULL)
{
fprintf(fout,"%d,%s%d\n",l1->id,l1->name,l1->point);
while(l1->data!=NULL)
{
l1->data->x=l1->data->x+1000;
l1->data->y=l1->data->y+500;
fprintf(fout,"%6.1f,%6.1f\n",l1->data->x,l1->data->y);
l1->data=l1->data->next;
}
l1=l1->next;
}
fclose(fout);
}
我实现了第一个问题。可是这个程序为什么只能执行一次?恳请高手指点 |
|