用C语言编写一个通讯录管理系统

Python031

用C语言编写一个通讯录管理系统,第1张

C语言编写一个通讯录管理系统的源代码如下:

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

/*定义保存通迅录的信息*/

structfriends

{

charname[20]/*名字*/

charprovince[20]/*省份*/

charcity[20]/*所在城市*/

charnation[20]/*民族*/

charsex[2]/*性别M/F*/

intage/*年龄*/

}

扩展资料

1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。

2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。

3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。

#include <cstdio>

#include <cmath>

#include <cstring>

#include <algorithm>

#include <iostream>

#include <cstring>

#include <cmath>

using namespace std

cout<<"如果需要此程序的改版,请私信或加我QQ:2416560314"<<endl

FILE *p,*p1

struct note{

char name[100]

char phone[100]

char mail[100]

}people[1000]

int main()

    {

        int n=0,i,j

        p=fopen("list.txt","r")

        if(p==NULL)

        {

            fclose(p)

            p=fopen("list.txt","w")

            fclose(p)

        }

        while(1)

        {

            n=0

            p=fopen("list.txt","r")

            while(fscanf(p,"%s%s%s",people[n].name,people[n].phone,people[n].mail)!=EOF)

                n++

            fclose(p)

            ///---------------

            int k

            cout<<"输入1读取,输入2输入"<<endl

            cin>>k

            if(k==1)

            {

                cout<<"输入信息"<<endl

                char s[100]

                cin>>s

                bool ok=0

                for(i=0i<strlen(s)i++)

                    if(s[i]>='0'&&s[i]<='9')

                      ok=1

                if(ok==0)

                {

                    //cout<<"通过姓名找到联系人"<<endl

                    //system("pause")

                    bool you=0

                    for(i=0i<ni++)

                        if(strcmp(s,people[i].name)==0)

                            {

                                you=1

                                cout<<"姓名"<<people[i].name<<endl

                                cout<<"电话号码"<<people[i].phone<<endl

                                cout<<"邮箱"<<people[i].mail<<endl

                            }

                    if(you==0)

                      cout<<"没有通过姓名找到联系人"<<endl

                }

                if(ok==1)

                {

                    //cout<<"通过电话找联系人"<<endl

                    //system("pause")

                    bool you=0

                    for(i=0i<ni++)

                        if(strcmp(s,people[i].phone)==0)

                            {

                                you=1

                                cout<<"姓名"<<people[i].name<<endl

                                cout<<"电话号码"<<people[i].phone<<endl

                                cout<<"邮箱"<<people[i].mail<<endl

                            }

                    if(you==0)

                      cout<<"没有通过电话找到联系人"<<endl

                }

            }

            if(k==2)

            {

                p1=fopen("list.txt","a+")

                char ss[1000]

                cout<<"请输入姓名"<<endl

                cin>>ss

                fprintf(p1,"%s\n",ss)

                cout<<"请输入电话"<<endl

                cin>>ss

                fprintf(p1,"%s\n",ss)

                cout<<"请输入邮箱"<<endl

                cin>>ss

                fprintf(p1,"%s\n",ss)

                fclose(p1)

            }

        }

        return 0

    }

/*

* main_tongxunlu.c

*

* Created on: 2011-6-21

* Author: zhanglujin

*/

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<conio.h>

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=0i<numi++)

{

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=0i<numi++)

{

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')

{