帮忙看看这个函数,我看着不太懂,谢啦!
void CreatPolyn(Polyn *pt)
{int a,b,c,zhi;Polyn s,l,k,p;char ss[20];FILE *file; float xi;
printf("0:return,1:Enter use keyboard,2:Enter use file\n");
scanf("%d",&a);
s=malloc(sizeof(Poly));
s->next=NULL;
*pt=s;k=s->next;p=s;
switch(a)
{case 1:printf("Enter the number of note\n");
scanf("%d",&b);
for(c=1;c<=b;c++)
{l=malloc(sizeof(Poly));
printf("\nEnter xishu&&zhishu\n");
scanf("%f%d",&l->xi,&l->zhi);
s=p;k=s->next;
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi==0)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
}
break;
case 2:printf("Enter file name\n");
scanf("%s",ss);
if((file=fopen(ss,"rt"))==NULL)
{printf("file could not been opened\n");return;}
fscanf(file,"%f,%d;",&xi,&zhi);
while(!feof(file))
{l=malloc(sizeof(Poly));
l->xi=xi;l->zhi=zhi;
s=p;k=s->next;
while(k&&k->zhi<l->zhi)
{k=k->next;s=s->next;}
if(k->zhi==l->zhi)
{k->xi+=l->xi;
if(k->xi==0)
{s->next=k->next;free(k);}
free(l);
}
else
{l->next=k;s->next=l;}
fscanf(file,"%f,%d;",&xi,&zhi);
}break;
case 0:return;
}
printf("Polyn has been created\n");
}
看看这个函数