#include<stdlib.h>
#include<string.h>
struct www
{
int num;
union
{
int i;
double j;
char c[10];
}catagory;
enum type{Interger=1,Real,String}ccc;
struct www*next;
};
enum type pri;
int main()
{
void countt(struct www*p1,struct www*p2);
void print(struct www*p2);
void sort(struct www*pp);
struct www*head;
struct www*p1,*p2;
p1=p2=(struct www*)malloc(15);
int n=0;
int i;
head=NULL;
while(n<=7)
{
n++;
if(n==1)head=p1;
else p2->next=p1;
switch(n)
{
case 1:strcpy(p1->catagory.c,"banana");
p1->ccc=String;break;
case 2:strcpy(p1->catagory.c,"apple");p1->ccc=String;break;
case 3:p1->catagory.i=122;p1->ccc=Interger;break;
case 4:p1->catagory.j=67.89;p1->ccc=Real;break;
case 5:p1->catagory.j=22.45;p1->ccc=Real;break;
case 6:strcpy(p1->catagory.c,"orange");p1->ccc=String;break;
case 7:p1->catagory.i=98;p1->ccc=Interger;break;
}
p2=p1;
p1=(struct www*)malloc(15);
print(p2);
}
p1=head;
p2=head;
sort(p1);
countt(p1,p2);
for(i=1;i<=7;i++)
free(p1+i);
return 0;
}
void print(struct www*p2)
{
if(p2->ccc==String)
printf("%-6s",p2->catagory.c);
if(p2->ccc==Interger)
printf("%-6d",p2->catagory.i);
if(p2->ccc==Real)
printf("%-6lf",p2->catagory.j);
printf("\n");
}
void countt(struct www*p1,struct www*p2)
{
int i,j=0,n=0,k=1;
struct www* temp,*head;
for(i=1;i<=7;i++)
{
p1->num=i;
p1=p1->next;
}
head=temp=p2;
while(j<=6)
{
j++;
while(k%3!=0)
{
n++;
if(n==1&&p1->num!=0)
{
temp=p1;
head=temp;
}
else if(p1->num!=0)
temp->next=p1;
if(p1->next==NULL)
{
p1=head;
n=0;
}
else p1=p1->next;
k++;
}
if(p1->next==NULL)
{
p1=head;
n=0;
}
else p1=p1->next;
k++;
}
printf("最后剩下的列表编号为%d\n内容为",temp->num);
switch(temp->num)
{
case 1:printf("%s",temp->catagory.c);break;
case 2:printf("%s",temp->catagory.c);break;
case 3:printf("%d",temp->catagory.i);break;
case 4:printf("%lf",temp->catagory.j);break;
case 5:printf("%lf",temp->catagory.j);break;
case 6:printf("%s",temp->catagory.c);break;
case 7:printf("%d",temp->catagory.i);break;
}
}
显示linker command failed ,但是我找不出错误 可以帮帮忙吗 谢谢