#include
#include
#include
#include
#define ASK(top)
#define LEN sizeof(ADDR)
extern int count;
typedef struct address
{char name[8];
char tel[20];
struct address *next;
}ADDR;
struct address *head;
struct address *p; int n;
ADDR *input()
{
p=head;
while(p!=NULL)
{scanf("%s %s\n",p->name,p->tel);
p=p->next;
n++;}
return head;
}
void display(ADDR *head)
{
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%s %s\n",p->name,p->tel);
p=p->next;
}while(p!=NULL);
}
ADDR del(ADDR *head)
{ char name[8];
if(head==NULL)
{printf("\nlist null!\n");return *head;}
p=head;
while(p!=NULL)
{
int j;char str1[8];char str2[8];
for(j=0;j {str1[j]=name[j];str2[j]=name[j];}
if(strcmp(str1,str2)==0)
{if(p==head) head=p->next;
else p=p->next;
printf("delete:%s %s\n",p->name,p->tel);
n=n-1;
}
else p=p->next;
}
return *head;
}
int handle_menu(ADDR *)
{
int c;
printf("\n1.input address's data\n");
printf("\n2.display address's data\n");
printf("\n3.delete address's data\n");
printf("\n4.Goodbye!");
printf("please input your selecion 1-5:");
scanf("%d\n",&c);
return c;
}
void main()
{
ADDR *top;
ASK(top);top=head;
top->next=NULL;
count=0;
handle_menu(top);
int d;
for(;;)
{d=handle_menu(top);
switch(d)
{case 1:input();break;
case 2:display(top);break;
case 3:del(top);break;
case 4:printf("Goodbye!");
default:printf("input error!please input again!\n");break;
}
}
}
extern int count;
在别的文件里有定义吗?
把链接的错误信息也贴上来吧
||=== 生成: Debug in test (compiler: GNU GCC Compiler) ===|
||In function 'del':|
|138|error: expected ';' before '{' token|
|146|error: expected expression before '}' token|
|146|error: expected expression before '}' token|
|137|warning: unused variable 'str2' [-Wunused-variable]|
|137|warning: unused variable 'str1' [-Wunused-variable]|
|131|warning: unused variable 'name' [-Wunused-variable]|
||In function 'handle_menu':|
|149|error: parameter name omitted|
|160|warning: return type of 'main' is not 'int' [-Wmain]|
||=== Build 失败了: 4 error(s), 4 warning(s) (0 minute(s), 0 second(s)) ===|
这是我复制后编译的信息。
count声明的地方呢?
我又修改了一下,好像没什么大问题了
#include
#include
#include
#include
#define ASK(top)
#define LEN sizeof(ADDR)
int n;
typedef struct address
{char name[8];
char tel[20];
struct address *next;
}ADDR;
struct address *head;
struct address *p;
ADDR *input()
{
p=head;
while(p!=NULL)
{scanf("%s %s\n",p->name,p->tel);
p=p->next;
n++;}return n;
return head;
}
void display(ADDR *head)
{
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%s %s\n",p->name,p->tel);
p=p->next;
}while(p!=NULL);
}
ADDR del(ADDR *head)
{ char name[8];
if(head==NULL)
{printf("\nlist null!\n");return *head;}
p=head;
while(p!=NULL)
{
int j;char str1[8];char str2[8];
for(j=0;j {str1[j]=name[j];str2[j]=name[j];}
if(strcmp(str1,str2)==0)
{if(p==head) head=p->next;
else p=p->next;
printf("delete:%s %s\n",p->name,p->tel);
n=n-1;
}
else p=p->next;
}
return *head;
}
int handle_menu(ADDR *head)
{
int c;
printf("\n1.input address's data\n");
printf("\n2.display address's data\n");
printf("\n3.delete address's data\n");
printf("\n4.Goodbye!");
printf("please input your selecion 1-5:");
scanf("%d\n",&c);
return c;
}
void main()
{
int d;
ADDR *top;
ASK(top);top=head;
top->next=NULL;
n=input();
handle_menu(top);
for(;;)
{d=handle_menu(top);
switch(d)
{case 1:input();break;
case 2:display(top);break;
case 3:del(top);break;
case 4:printf("Goodbye!");
default:printf("input error!please input again!\n");break;
}
}
}