自己写的,看一下
// 头文件部分
//============================
#include <stdioh>
#include <windowsh>
#include <stdlibh>
#include <conioh>
// 初始化数据部分
int Menu();
void Start();
void Write();
void Read();
void Search();
void Detele();
void beauty();
void Rework();
void Lock();
int Judge();
//============================
struct Student{
char name[20];
char Tel[20];
char QQ[20];
int age;
}xy[100];
char wenjian[10000];
char Number[10];
char number=0;
int GOTO;
//
int main()
{
Start();
for(;;)
{
GOTO=Menu();
if(GOTO==1)
{
for(;;)
{
Write();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==2)
{
for(;;)
{
Read();
system("pause");
break;
}
}
if(GOTO==3)
{
for(;;)
{
Search();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==4)
{
for(;;)
{
Rework();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==5)
{
Detele();
break;
}
if(GOTO==6)
{
beauty();
break;
}
if(GOTO==7)
{
}
if(GOTO==8)
{
printf("");
break;
}
if(GOTO==9)
{
printf("\t\t\t退出系统\n\n");
return 0;
}
if(GOTO==0)
{
printf("");
break;
}
}
// beauty();
//
// Write();
// Read();
// Search();
// Rework();
// Detele();
return 0;
}
void Write()
{
scanf("%s",&xy[number]name);
printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[number]Tel);
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[number]QQ);
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[number]age);
FILE file;
if((file=fopen("Friendtxt","rt"))==NULL)
{
file=fopen("Friendtxt","wt");
fprintf(file,"%-20s%-20s%-20s%-20s","姓名","电话","QQ","年龄");
}
file=fopen("Friendtxt","at");
fprintf(file,"%-20s%-20s%-20s%-20d\n",xy[number]name,xy[number]Tel,xy[number]QQ,xy[number]age);
fclose(file);
number++;
Number[0]=number;
FILE Sta;
if((Sta=fopen("numbertxt","r"))=NULL)
{
Sta=fopen("numbertxt","wt");
exit(1);
}
Sta=fopen("numbertxt","wt");
fprintf(Sta,"%d",Number[0]);
fclose(Sta);
}
void Read()
{
printf("\t\t\t您通讯录中一共有%d位好友\n",Number[0]);
FILE read;
if((read=fopen("Friendtxt","r"))=NULL)
{
printf("\t\t\t您通讯中当前没有好友,请返回添加\n");
}
read=fopen("Friendtxt","rt");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
for(int i=0;i<number;i++)
{
fscanf(read,"%s%s%s%d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,&xy[i]age);
printf("%-20s%-20s%-20s%-20d\n",xy[i]name,xy[i]Tel,xy[i]QQ,xy[i]age);
}
/ fread(wenjian,10000,1,read);
for(int i=0;i<number80+80;i++)
{
printf("%c",wenjian[i]);
}
printf("\n");
/
fclose(read);
}
void beauty()
{
int d;
do{
printf("choose");
scanf("%d",&d);
}while(d<1&&d>5);
if(d==1)
{
system("color 27");
printf("===1===");
}
if(d==2)
{
system("color 37");
printf("===2===");
}
if(d==3)
{
system("color 47");
printf("===3===");
}
if(d==4)
{
system("color 57");
printf("===4===");
}
if(d==5)
{
system("color 67");
printf("===5===");
}
}
void Start()
{
FILE Start;
if((Start=fopen("numbertxt","r"))==NULL)
{
Start=fopen("numbertxt","w");
number=0;
Number[0]=number;
fscanf(Start,"%d",&Number[0]);
printf("\t\t\t您的通讯录中还没有任何好友,赶快添加吧此次 *** 作需要重新运行程序。\n");
exit(1);
}
Start=fopen("numbertxt","r");
fscanf(Start,"%d",&Number[0]);
number=Number[0];
fclose(Start);
}
void Search()
{
int change=0;
char Searchname[20];
printf("\t\t\t输入要查找的好友的名字\n\n");
scanf("%s",&Searchname);
fflush(stdin);
printf("\t\t\t您要查找的好友是 %s \n\n",Searchname);
FILE Search;
Search=fopen("Friendtxt","rt");
for(int i=0;i<=number;i++)
{
fscanf(Search,"%s%s%s%d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,&xy[i]age);
if(strcmp(xy[i]name,Searchname)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,xy[i]age);
change=1;
}
fclose(Search);
}
if(change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}
void Rework()
{
char Rework[20];
printf("\t\t\t输入要修改的好友的名字\n\n");
scanf("%s",&Rework);
printf("\t\t\t您要修改 %s 的信息\n\n",Rework);
int Change=0;
FILE Search;
Search=fopen("Friendtxt","rt");
for(int i=0;i<=number;i++)
{
fscanf(Search,"%s%s%s%d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,&xy[i]age);
if(strcmp(xy[i]name,Rework)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
Change=1;
int Choose;
printf("%-20s%-20s%-20s%-20d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,xy[i]age);
//---------------------------------------------------------------------
do
{
printf("\t\t\tchoose\t\t\t1-----3");
scanf("%d",&Choose);
}while(Choose>3||Choose<1);
if(Choose==1){
printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[i]Tel);
}
if(Choose==2)
{
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[i]QQ);
}
if(Choose==3)
{
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[i]age);
}
Search=fopen("Friendtxt","wt");
for(int sta=0;sta<i;sta++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[sta]name,xy[sta]Tel,xy[sta]QQ,xy[sta]age);
}
if(sta==i)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i]name,xy[i]Tel,xy[i]QQ,xy[i]age);
i++;
}
for(i;i<=number;i++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i]name,xy[i]Tel,xy[i]QQ,xy[i]age);
}
printf("\t\t\t修改后的信息为:\n\n");
Read();
}
fclose(Search);
}
if(Change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}
void Detele()
{
int change=0;
char delete_friend[20];
printf("\t\t\t输入要删除的好友的名字\n\n");
scanf("%s",&delete_friend);
fflush(stdin);
printf("\t\t\t您要删除的好友是 %s \n\n",delete_friend);
FILE DeleteF;
DeleteF=fopen("Friendtxt","rt");
for(int i=0;i<=number;i++)
{
fscanf(DeleteF,"%s%s%s%d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,&xy[i]age);
if(strcmp(xy[i]name,delete_friend)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i]name,&xy[i]Tel,&xy[i]QQ,xy[i]age);
change=1;
DeleteF=fopen("Friendtxt","wt");
for(int st=0;st<i;st++)
{
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[st]name,xy[st]Tel,xy[st]QQ,xy[st]age);
}
i++;
for(i;i<=number;i++)
{
printf("%-20s%-20s%-20s%-20d\n",xy[i]name,xy[i]Tel,xy[i]QQ,xy[i]age);
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[i]name,xy[i]Tel,xy[i]QQ,xy[i]age);
}
}
//--------------------------------------------------------------------------------
if(change==1)
{
printf("\t\t\t删除后的通讯录信息为:\n\n");
number--;
Number[0]=number;
FILE St;
if((St=fopen("numbertxt","r"))=NULL)
{
St=fopen("numbertxt","wt");
exit(1);
}
St=fopen("numbertxt","wt");
fprintf(St,"%d",Number[0]);
fclose(St);
fclose(DeleteF);
Start();
Read();
}
}
if(change==0)
{
printf("\t\t\t您要删除的好友不存在。\n");
}
}
void Lock()
{
}
int Menu()
{
printf("\t\t欢迎进入通讯管理界面\n\n");
printf("\t\t\t1添加我的好友\n");
printf("\t\t\t2显示所有好友\n");
printf("\t\t\t3查找我的好友\n");
printf("\t\t\t4修改好友信息\n");
printf("\t\t\t5删除我的好友\n");
printf("\t\t\t6设置背景颜色\n");
printf("\t\t\t7设置管理密码\n");
printf("\t\t\t8使用注意事项\n");
printf("\t\t\t9退出通讯系统\n");
printf("\t\t\t0作者想说的话\n");
printf("\t\t\n\n");
do{
printf("\t\t\t请输入你的选择:\n\n");
scanf("%d",&GOTO);
}while(GOTO>9||GOTO<1);
return GOTO;
}
int Judge()
{
char JUDGE;
do
{
printf("\t\t\t是否继续当前 *** 作\n\n Y(yes) / N(no)\n");
printf("\t\t\t输入你的选择\n");
JUDGE=getch();
if(JUDGE=='y'||JUDGE=='Y')
{
return 1;
}
if(JUDGE=='n'||JUDGE=='N')
{
return 2;
}
}while(JUDGE!='y'||JUDGE!='n');
}
#include<stdioh>
#include<stringh>
#include<windowsh>
#define M 500
struct Man //定义结构体
{
char Name[8]; //名字
char Depart[20]; //工作单位
char QQ[10]; //QQ号码
char Email[30]; //邮箱
};
void text(); //相当于主函数
void text1(); //菜单输出
char text2(); //开始的版权信息输出
int Delete(Man Man[], int Size);//删除信息
void Display(Man man[]); //显示所有记录
void getch();
int Insert(Man Man[], int Size); //插入模块
void Modify(Man Man[], int Size); //修改模块
int S_asname(Man Man[], int Size, int n); //查找信息
void S_asqq(Man Man[], int Size); //按QQ查找模块
int Save(Man Man[], int Size); //把数据写入文件
int Scan(Man Man[]); //从文本中读取数据
void main() //主函数
{
text(); //(这边纯属蛋疼,最多加长系统运行时间)
}
void text() //相当于主函数
{
Man man[M]; //500人的结构体数组
char control=0; //菜单选择控制变量
int size=0; //保存当前已有的记录
if ( text2() ) //这边可不要if,直接调用text2,显示版权信息。
{
size=Scan(man); //判断文件是否存在
while(1) //菜单生成
{
text1(); //菜单显示
scanf(
#include<stdioh>
#include<stdlibh>
#include<stringh>
#include<conioh>
struct record
{
char name[20]; //姓名
char phone[12]; //电话
char adress[50]; //地址
char postcode[8]; //邮政编码
char e_mail[20]; //电子邮件。
}student[100]; //假设最大数为100
//定义全局变量num,表示已经输入的人数 。
int num; //这里使用数组解决通讯录的问题,实际上使用链表更好。
int menu_select()
{
char s[80];
int a;/定义整形变量/
system("cls");
printf("\t\t欢迎进入通讯管理界面\n\n");
printf("\t\t\t0 输入记录\n");
printf("\t\t\t1 显示记录\n");
printf("\t\t\t2 按姓名查找\n");
printf("\t\t\t3 按电话号码查找\n");
printf("\t\t\t4 插入记录 \n");
printf("\t\t\t5 按姓名排序\n");
printf("\t\t\t6 删除记录\n");
printf("\t\t\t7 Quit\n");
printf("\t\t\n\n");
do{
printf("Enter you choice(0~7):");
scanf("%s",s);
a=atoi(s);
}
while (a<0 || a>7);
return a;
}
int adduser()
{
printf("\t\t\t 请输入用户信息 \n");
printf("\t\t\t输入姓名:\n");
scanf("%s",student[num]name);
printf("\t\t\t输入电话号码:\n");
scanf("%s",student[num]phone);
printf("\t\t\t输入地址:\n");
scanf("%s",student[num]adress);
printf("\t\t\t输入邮编:\n");
scanf("%s",student[num]postcode);
printf("\t\t\t输入e-mail:\n");
scanf("%s",student[num]e_mail);
num++;
printf("\t\t\t是否继续添加(Y/N):\n");
if(getch()=='y' || getch()=='Y')
adduser();
return(0);
}
void list()
{
int i;
system("cls");
if(num!=0)
{
printf("\t\t\t 以下为通讯录所有信息\n");
for (i=0;i<num;i++)
{
printf("\t\t\t姓名:%s\n",student[i]name);
printf("\t\t\t电话:%s\n",student[i]phone);
printf("\t\t\t地址:%s\n",student[i]adress);
printf("\t\t\t邮编:%s\n",student[i]postcode);
printf("\t\t\te-mail:%s\n",student[i]e_mail);
if(i+1<num)
{
system("pause");
}
}
printf("\t\t\t\n");
}
else
printf("\t\t\t通讯录中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单:\n");
getch(); //这里是无回显的输入字符,你输入的字符不会显示在屏幕上。
return;
}
int searchbyname()
{
int mark=0;
int i;
printf("\t\t\t 按姓名查找 \n");
char name[20];
printf("\t\t\t请输入姓名:\n");
scanf("%s",name);
for(i=0;i<num;i++)
{
if (strcmp(student[i]name,name)==0)
{
printf("\t\t\t 以下是您查找的用户信息 \n");
printf("\t\t\t姓名: %s",student[i]name);
printf("\t\t\t电话: %s",student[i]phone);
printf("\t\t\t地址: %s",student[i]adress);
printf("\t\t\te-mail:%s",student[i]e_mail);
printf("\t\t\t\n");
mark++;
if((i+1)<num)
{
printf("\t\t\t是否继续查找相同名字的用户信息:(y/n)\n");
if(getch()=='y' || getch()=='Y')
{
continue;
}
else
return(0);
}
else
{
printf("\t\t\t按任意键返回主菜单");
getch();
return(0);
}
}
}
if(mark == 0)
{
printf("\t\t\t没有相同姓名的用户纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return 0;
}
int searchbyphone()
{
int mark=0;
int i;
printf("\t\t\t 按电话查找 \n");
char phone[10];
printf("\t\t\t请输入电话号码:\n");
scanf("%s",phone);
for(i=0;i<num;i++)
{
if (strcmp(student[i]phone,phone)==0)
{
printf("\t\t\t 以下是您查找的用户信息 \n");
printf("\t\t\t姓名: %s",student[i]name);
printf("\t\t\t电话: %s",student[i]phone);
printf("\t\t\t地址: %s",student[i]adress);
printf("\t\t\te-mail:%s",student[i]e_mail);
printf("\t\t\t\n");
printf("\t\t\t按任意键返回主菜单\n");
mark++;
getch();
return(0);
}
}
if (mark==0)
{
printf("\t\t\t没有改用户的信息\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return(0);
}
void deletebyphone()
{
int i,j;
int deletemark=0;
char phone[20];
printf("\t\t\t请输入要删除用户电话号码:\n");
scanf("%s",phone);
if(num==0)
{
printf("\t\t\t对不起,文件中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return;
}
for (i=0;i<num;i++)
{
if (strcmp(student[i]phone,phone)==0)
{
printf("\t\t\t以下是您要删除的用户纪录:\n");
printf("\t\t\t姓名: %s",student[i]name);
printf("\t\t\t电话: %s",student[i]phone);
printf("\t\t\t地址: %s",student[i]adress);
printf("\t\t\te-mail:%s",student[i]e_mail);
printf("\t\t\t是否删除(y/n)");
if (getch()=='y' || getch()=='Y')
{
for (j=i;j<num-1;j++)
student[j]=student[j+1];
num--;
deletemark++;
printf("\t\t\t删除成功");
printf("\t\t\t是否继续删除(y/n)");
if (getch()=='y' || getch()=='Y')
deletebyphone();
return;
}
else
return;
}
continue;
}
if (deletemark==0)
{
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除(y/n)");
if(getch()=='y' || getch()=='Y')
deletebyphone();
return;
}
return;
}
void deletebyname()
{
int a=0;
int findmark=0;
int j;
int deletemark=0;
int i;
char name[20];
printf("\t\t\t请输入要删除用户姓名:\n");
scanf("%s",name);
for (i=a;i<num;i++)
{
if(strcmp(student[i]name,name)==0)
{
printf("\t\t\t以下是您要删除的用户纪录:");
findmark++;
printf("\t\t\t________________________________");
printf("\t\t\t姓名: %s",student[i]name);
printf("\t\t\t电话: %s",student[i]phone);
printf("\t\t\t地址: %s",student[i]adress);
printf("\t\t\te-mail:%s",student[i]e_mail);
printf("\t\t\t________________________________");
printf("\t\t\t是否删除(y/n)");
if (getch()=='y' || getch() == 'Y')
{
for(j=i;j<num-1;j++)
student[j]=student[j+1];
num--;
deletemark++;
printf("\t\t\t删除成功");
if((i+1)<num)
{
printf("\t\t\t是否继续删除相同姓名的用户信息(y/n)");
if (getch()=='y')
{
a=i;
continue;
}
}
printf("\t\t\t是否继续删除(y/n)");
if (getch()=='y')
deletebyname();
return;
}
if((i+1)<num)
{
printf("\t\t\t是否继续删除相同姓名的用户信息(y/n)");
if (getch()=='y' || getch() == 'Y')
{
a=i;
continue;
}
}
}
else
continue;
}
if ((deletemark==0)&&(findmark==0))
{
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除(y/n)");
if(getch()=='y' || getch() == 'Y')
deletebyphone();
return;
}
else if (findmark!=0)
{
printf("\t\t\t没有重名信息");
printf("\t\t\t没有该用户的纪录");
printf("\t\t\t是否继续删除(y/n)");
if(getch()=='y' || getch() == 'Y')
deletebyphone();
return;
}
}
int dele()
{
char choic;
printf("\t\t\t1-按电话号码删除 2-按姓名删除");
printf("\t\t\t请选择:");
choic=getch();
switch (choic)
{
case '1':deletebyphone();break;
case '2':deletebyname();break;
}
return(0);
}
int sortbyname() //按姓名进行排序
{
int i,j;
struct record tmp;
for (i=1;i<num;i++)
{
if(strcmp(student[i]name,student[i-1]name)<0)
{
tmp=student[i];
j=i-1;
do
{
student[j+1]=student[j];
j--;
}while ((strcmp(tmpname,student[j]name)<0&&j>=0));
student[j+1]=tmp;
}
}
printf("\t\t\t排序成功,是否显示(y/n)");
if (getch()=='y')
list();
return(0);
}
int main()
{
printf("\t\t\n");
printf("\t\twelcome to TONGXUNLU \n");
printf("\t\t###########code by XXXXX ###################\n");
printf("\t\t\n");
printf("按任意键进入主菜单\n");
getch();
int selectnum;
while(1)
{
selectnum = menu_select();
switch(selectnum)
{
case 0:
{
adduser();
break;
}
case 1:
{
list();
break;
}
case 2:
{
searchbyname();
break;
}
case 3:
{
searchbyphone();
break;
}
case 4:
{
adduser(); //这里插入,应该能指定位置,不过意义不大,所以和添加记录一样了。
break;
}
case 5:
{
sortbyname();
break;
}
case 6:
{
dele();
break;
}
case 7:
{
printf("BYE BYE!\n");
system("pause");
getchar();
exit(0);
}
}
}
getchar();
return 0;
}
以上就是关于用c语言编写通讯录全部的内容,包括:用c语言编写通讯录、编写建立同学通讯录包括姓名和电话号码的c 语言程序、用c语言程序设计一个学生通讯录系统等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)