人在江湖【走】,怎能不挨【刀】;为了能活【口】,唯有把己【超】!come on...
呵呵。。。谢谢你的指导。。。看来还是躲在宿舍里,静下心写的东西有点用。。。上了机房忙着忙那的。全部颠覆了!
楼上的俩位.本论坛有水区!
饿。静态外部变量为什么会每次都回0呢????
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <string.h>
#define MAX 3 //通讯录组的大小
struct day
{
int month;
int day1;
};
struct mydata
{
char name[20];
struct day birthday;
char telnum[13];
};
static int g;//我把这边g的定义为静态外部变量。就是希望它不会随便改变。一共输入用户的个数就为g。
void input(struct mydata a[],int g); //调用输入函数
void output(struct mydata a[],int g); //调用输出函数
void search(struct mydata a[],int g); //调用查找函数
void array(struct mydata a[],int g); //调用排列函数
void delete1(struct mydata a[],int g); //调用删除函数
int main(void)
{
struct mydata a[MAX];
while(1)
{
int i;
printf("1.input the data.\n");
printf("2.output the data.\n");
printf("3.search the data.\n");
printf("4.array the data.\n");
printf("5.delete the data.\n");
printf("6.return to system.\n");
printf("Please selete:");
scanf("%d",&i);
getchar();
switch (i)
{
case 1:input(a,g);break;
case 2:output(a,g);break;
case 3:search(a,g);break;
case 4:array(a,g);break;
case 5:delete1(a,g);break;
case 6:exit(0);
}
}
return 0;
}
void input(struct mydata a[],int g) //输入data
{
char ch;
printf("input the data:");
do
{
printf("\ninput the name:");
gets(a[g].name);
printf("\ninput the birthday(mm-dd):");
scanf("%d-%d",&a[g].birthday.month,&a[g].birthday.day1);
getchar();
printf("\ninput the telphone number:");
gets(a[g].telnum);
printf("countuie?(press n or N to quie)");
scanf("%c",&ch);
getchar();
}while((ch!=78)&&(ch!=110)&&(++g<MAX));
g++;
printf("%d",g);
}
void array(struct mydata a[],int g) //排列
{
int i,j;
struct mydata t;
for(i=0;i<g-1;i++) //让人名从a-z排列
{
for(j=1;j<g;j++)
{
if(strcmp(a[i].name,a[j].name)>0)
{t=a[i];a[i]=a[j];a[j]=t;}
}
}
}
void output(struct mydata a[],int g) //输出
{
int i;
for(i=0;i<=g-1;i++) //输出所有人物!
{
printf("%s's birthday is %d.%d telphone number is %s.\n",
a[i].name,a[i].birthday.month,a[i].birthday.day1,a[i].telnum);
}
}
void search(struct mydata a[],int g) //查找
{
char keyname[20];int i,flag=1;
struct mydata t;
printf("input the search name:"); //查找人物!
gets(keyname);
for(i=0;(i<=g-1)&&flag;i++)
{
if(strcmp(keyname,a[i].name)!=0);
else
{
printf("Find the data:%s's birthday is %d.%d telphone number is %s.\n",
a[i].name,a[i].birthday.month,a[i].birthday.day1,a[i].telnum);
flag=0;
}
}
if(flag)printf("Can't find the data!!\n");
}
void delete1(struct mydata a[],int g) //删除
{
char keyname[20];int i,flag=1;
printf("input the search name:");
gets(keyname);
for(i=0;(i<=g-1)&&flag;i++)
{
if(strcmp(keyname,a[i].name)!=0);
else
{
a[MAX]=a[i];g-=1;
printf("the data is delete!!!\n");
flag=0;
}
}
array(a,g);
if(flag)printf("Can't find the data!!\n");
}
[此贴子已经被作者于2006-6-28 14:42:52编辑过]