TC Linker error,求解决
连接时显示:“Linker error:Undefined symbol '_count'in module record.c”我的count在record.h已经“extern int count;”声明过了。
以下为TC代码:
#include<record.h>
void main()
{ADDR *top;
ASK(top);
top->next=NULL;
count=0;
for(;;)handle_menu(top);
}
ADDR *input(ADDR *top)
{ADDR *p1,*p2;
if(top->next==NULL)
{p1=p2=(ADDR *)malloc(LEN);
top=NULL;
while(p1->name[0]!='0')
{count+=1;
if(count==1) top=p1;
else p2->next=p1;
p2=p1;
p1=(ADDR *)malloc(LEN);
printf("Please input your record:\n");
printf("Name:");
gets(p2->name);
printf("Phonenumber:");
gets(p2->tel);
}
}
else
{while(p1->name[0]!='0')
{count+=1;
p2->next=p1;
p2=p1;
p1=(ADDR *)malloc(LEN);
printf("Please input your record:\n");
printf("Name:");
gets(p2->name);
printf("Phonenumber:");
gets(p2->tel);
}
}
p1=p2;
p2->next=NULL;
return(top);
}
void display(ADDR*top)
{ADDR *p;
printf("\nThere are %d records:\n",count);
printf(" name phonenumber\n");
p=top;
if(p!=NULL)
do
{printf("%6s %18s\n",p->name,p->tel);
p=p->next;
}while(p!=NULL);
else printf("No list!\n");
}
void del(ADDR*top)
{int cn;
char choose[20];
ADDR *p1,*p2;
if(count==0) printf("\n List null!\n");
printf("Record delete:");
printf("1.name.\n");
printf("2.telephone number.\n");
printf("Please enter the number:");
gets(choose);
while(1)
{cn=atoi(choose);
if(cn!=1&&cn!=2)
{printf("Input error!Please choose 1-2 again:");
gets(choose);
}
else break;
}
p1=top;
switch(cn)
{case 1:{while(strcmp(p1->name,choose)!=0)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->name,choose)==0)
{if(p1==top) top=p1->next;
else
{p2->next=p1->next;
p1=p2->next;
}
printf("Deleted.");
count-=1;
}
else printf("Can't find the name!");
if(count==0)
{ASK(top);
top->next=NULL;
}
p2=p1;
}break;
case 2:{while(strcmp(p1->tel,choose)==0)
{p2=p1;
p1=p1->next;
}
if(strcmp(p1->tel,choose)!=0)
{if(p1==top)top=p1->next;
else
{p2->next=p1->next;
p1=p2->next;
}
printf("Deleted.");
count-=1;
}
else printf("Can't find the telephone number!");
if(count==0)
{ASK(top);
top->next=NULL;
}
p2=p1;
}break;
}
}
int menu_select(void)
{int chose=0;
printf("Menu\n");
printf("1.Input a record.\n");
printf("2.Delete a record.\n");
printf("3.Display all records.\n");
printf("4.Exit.\n");
printf("Please enter the num:\n");
scanf("%d",chose);
return(chose);
}
void handle_menu(ADDR *top)
{switch(menu_select())
{case 1:top=input(top);break;
case 2:del(top);break;
case 3:display(top);break;
case 4:break;
default:{printf("Error!please enter again.\n");switch(menu_select());}
}
}
看了老半天,还是没找到问题所在-。-