再下写的一个通讯录:
里面包括插入,删除,输入,查找。帮忙改错。
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct date
{
int year;
int month;
int day;
};
struct student
{
char name[20];
long num;
char sex[6];
struct date birthday;
long tel;
long QQ;
struct student *next;
}s[5],*head,*this,*new;
main()
{
void input();
void serch();
void insert();
void del();
int n,i;
printf(" please chose one \n");
printf(" 1 please input student infomation\n");
printf(" 2 serch student infomation\n");
printf(" 3 insert student infomation\n");
printf(" 4 delete student infomation\n");
printf(" 5 exit student system\n");
scanf("%d",&i);
switch(i)
{
case 1: input();break;
case 2: serch();break;
case 3: insert();break;
case 4: del();break;
default:break;
}
}
input(void)
{
char a[20];
int i;
for(i=0;i<5;i++)
{
printf("please student name:");
gets(s[i].name);
printf("please input student num:");
gets(a);s[i].num=atol(a);
printf("please sex:f/m:");
gets(student[i].sex);
printf("please brithday:");
scanf("%d",s[i].brithday.year);
scanf("%d",s[i].brithday.month);
scanf("%d",s[i].brithday.day);
printf("please input tel num:");
gets(a);s[i].tel=atol(a);
printf("please input QQ:");
gets(a);student[i].QQ=atol(a);
}
}
insert()
{
char a[20];
new=(struct student)malloc(sizeof(struct student));
if(head==NUll)
head=new;
else
{
this=head;
while(this->next!=NUll)
this=this->next;
this->next=new;
}
this=new;
printf("input name :");
gets(this->name);
printf("input num:");
gets(this->num);
printf("inpue sex:");
gets(this->sex);
printf("input birthday year:");
scanf("%d",&this->birthday->year);
printf("input brithday month:");
scanf("%d",&this->brithday->month);
printf("input birthday day:");
scanf("%d",&this->birthday->day);
printf("input tel num:");
gets(a);this->tel=atol(a);
printf("input QQ num:");
gets(a);this->QQ=atol(a);
this->next=NULL;
}
serch()
{
char a[20];
long i;
printf("input num:");
gets(a);i=atol(a);
if(head==NULL)
printf("no student:");
else
{
this=head;
while(this->next!=i)
this=this->next;
puts(this->name);
printf("%ld",this->num);
puts(this->sex);
printf("%d %d %d",this->birthday->year,this->birthday->month,this->birthday.day);
printf("%ld",this->tel);
printf("%ld",this->QQ);
}
this=this->next;
}
del()
{
char a[20]
int j;
long i;
gets(a),i=atol(a);
this=head;
if(head!=NULL)
printf("no student");
else
{
for(i=0;i<100;i++)
if(s[i]==i)
s[i-1]->next=s[i+1];
}
}