关于输入档案程序的错误
我用C++软件的F4检查功能,第一下是说我switch(num)里的一个括号有问题,但是我看了没问题啊,也没找出错的,请大家帮我找找错,谢谢大家,请问,如果我要在后面添加一个搜索功能,应该怎么写呢?#include <stdio.h>
#include <stdlib.h>
struct directory{
char name[20];
char address[30];
char telNum[9];
struct directory* next;
};
struct directory* head=NULL;
struct directory* tail=NULL;
struct directory* i=NULL;
void insert(void);
void del(void);
void print(void);
void main(void)
{
int num;
while(1){
printf("**menu**\n");
printf("1.input\n");
printf("2.delete\n");
printf("3.print\n");
printf("4.exit\n");
printf("\n select number:");
scanf("%d",&num);
switch(num){
case 1:
insert();
break;
case 2:
del();
break;
case 3:
print();
break;
case 4:
exit(1);
break;
default:
printf("number select error.\n");
break;
}
}
}
void insert(void)
{
char iname[20];
char iaddress[30];
char iphone[9];
printf ("name:");
scanf ("%s",iname);
printf ("address:");
scanf ("%s",iaddress);
printf ("phone:");
scanf ("%s",iphone);
i = (struct directory*) malloc ( sizeof ( struct directory ));
if ( head==NULL ){
head=i;
}
else{
tail->next=i;
}
strcpy (i->name,iname);
strcpy (i->address,iaddress);
strcpy (i->telNum,iphone);
i->next=NULL;
tail=i;
}
void del(void)
{
char iname[20];
struct directory* tempnode;
struct directory* afternode;
printf("deletename:");
scanf("%s",iname);
afternode=head;
while (afternode!=NULL){
if ( !strcmp (afternode->name,iname)){
if (afternode==head){
head=afternode->next;
free( afternode);
return;
}
else{
tempnode->next=afternode->next;
free (afternode);
return;
}
}
tempnode=afternode;
afternode=afternode->next;
}
printf("%s is Not exist directory in space\n",iname);
}
void print(void)
{
struct directory* temptail;
if(head==NULL)
printf("Not exist directory in space.\n");
else{
temptail=head;
printf("name\t address\t phone\n");
while(temptail!=NULL){
printf("-----------------------------\n name:%s\t address:%s\t phone:%s\n-----------------------------\n",temptail->name,temptail->address,temptail->telNum);
temptail=temptail->next;
}
}
}
[[it] 本帖最后由 hopepark 于 2008-11-4 14:19 编辑 [/it]]