C语言通讯录(初级版)

这里是一个简单的通讯录,固定为1000容量,不能动态增长,不能写入文件。初级版本。

#define _CRT_SECURE_NO_WARNINGS  1

#include<stdio.h>
#include<string.h>

int count = 0;

void menu()
{
    printf("**************************************\n");
    printf("***********1.添加联系人信息***********\n");
    printf("***********2.删除指定联系人信息*******\n");
    printf("***********3.查找指定联系人信息*******\n");
    printf("***********4.修改指定联系人信息*******\n");
    printf("***********5.显示所有联系人信息*******\n");
    printf("***********6.清空所有联系人***********\n");
    printf("***********7.以名字排序所有联系人*****\n");
    printf("***********0.******退出***************\n");
    printf("**************************************\n");
}

typedef struct teldir
{
    char name[10];
    char add[10];
    char sex[5];
    char num[12];
    int age;

}dir;

dir stu[1000] = { "0", "0", "0", "0", 0 };

void input()//添加
{
    printf("请输入添加联系人的信息\n");
    scanf("%s %s %s %s %d", &stu[count].name, &stu[count].add,
        &stu[count].sex, &stu[count].num, &stu[count].age);
    count++;
    printf("添加成功!");
}

void show_all()//显示全部
{
    int i = 0;
    printf("姓名*******地址******性别***电话**********年龄**\n");
    for (i = 0; i< count+1; i++)
    {
        if (stu[i].age)
        {
            printf("%-10s %-10s %-5s %-12s %d\n", stu[i].name, stu[i].add,
                stu[i].sex, stu[i].num, stu[i].age);
        }
    }
}

void deleted()//删除指定对象的信息
{
    int flag = 0;
    int i = 0;
    dir test;
    dir test1 = { "0", "0", "0", "0", 0 };
    printf("请输入要删除对象的姓名\n");
    scanf("%s", &test.name);
    for (i = 0; i < count + 1; i++)
    {
        if (strcmp((stu[i].name), (test.name)) == 0)
        {
            stu[i] = test1;
            printf("删除成功!");
            flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("没有此联系人,请确认\n");
    }
}

void lookfor()//查找指定对象的信息
{
    int flag = 0;
    int i = 0 ;
    dir test;
    printf("请输入指定对象的姓名\n");
    scanf("%s", &test.name);
    for (i = 0; i < count + 1; i++)
    {
        if (strcmp((stu[i].name), (test.name)) == 0)
        {
            printf("%-10s %-10s %-5s %-12s %d\n", stu[i].name, stu[i].add,
                stu[i].sex, stu[i].num, stu[i].age);
            flag = 1;
        }
        else
            ;
    }
    if (flag == 0)
    {
        printf("没有此联系人\n");
    }

}

void update()//更新信息
{
    int flag = 0;
    int i = 0;
    dir test;
    printf("请输入要更改对象的姓名\n");
    scanf("%s", &test.name);
    for (i = 0; i < count + 1; i++)
    {
        if (strcmp((stu[i].name), (test.name)) == 0)
        {
            printf("请输入更新后的信息\n");
            scanf("%s %s %s %s %d", &stu[i].name, &stu[i].add,
                &stu[i].sex, &stu[i].num, &stu[i].age);
            printf("更新成功!");
            flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("没有此联系人,请确认\n");
    }

}
void delete_all()//清空
{
    memset(stu, 0, sizeof(stu));
    printf("清空完成!");
};
void sort_byname()//按姓名排序
{
    //int i = 0;
    //dir test;
    //for (i = 0; i, count + 1; i++)
    //{
    //  if (strcmp(stu[i].name, stu[i + 1].name) < 0)
    //  {
    //      memmove(&test, &stu[i], sizeof(stu));
    //      memmove( &stu[i],&stu[i+1], sizeof(stu));
    //      memmove(&stu[i+1], &test, sizeof(stu));
    //  }
    //}
    printf("此功能暂时关闭!");
}

int main()
{
    int i = 0;
    menu();
    while (i+1)
    {
        printf("请选择操作\n");
        scanf("%d", &i);
        switch (i)
        {
        case 0:
            return 0;
            break;
        case 1:
            input();
            break;
        case 2:
            deleted();
            break;
        case 3:
            lookfor();
            break;
        case 4:
            update();
            break;
        case 5:
            show_all();
            break;
        case 6:
            delete_all();
            break;
        case 7:
            sort_byname();
            break;
        default:
            printf("输入错误\n");
            break;
        }
    }   
}
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值