c语言实现通讯录

该程序是一个简单的C语言实现的联系人管理应用。它包含添加、删除和搜索联系人的功能。用户可以输入姓名和电话号码来添加新联系人,按姓名删除联系人,或搜索特定联系人的信息。程序使用自定义结构体存储联系人数据,并在内存中管理这些数据。
摘要由CSDN通过智能技术生成
#include"contact.h"


void function(int num1,void * contact)
{
    int count = 0;
    char c;
    if (num1 == 1)
    {
        
        
        while ((*((char*)contact)+count) != 0)
        
            count = count + 14;
        
        printf("please enter your name");
        scanf("%s", (char*)contact+count);
        while ((c = getchar()) != '\n');
        printf("please enter your number");
        scanf("%d", (unsigned int*)((char*)contact + count + 10));

    }
    else if (num1 == 2)
    {
        char arr[10];
        long int arr1 = 0;
        printf("please enter the name of the person to be deleted");
        scanf("%s", arr);
        while ((c = getchar()) != '\n');
        while (strncmp((char*)contact+count, arr, 10) )
        {
            count = count + 14;

        }
        strcpy((char*)contact+count,arr);
        memcpy((char*)contact+count+10, &arr1,4);
    }
    else
    {
        printf("please enter the name of thecontact");
        char arr[10];
        
        
        scanf("%s", arr);
        while ((c = getchar()) != '\n');
        while (strncmp((char*)contact + count, arr, 10))
        {
            count = count + 14;

        }
        printf("%s%u", (char*)contact + count, *(unsigned int*)((char*)contact + count + 10));
        

    }

}
#include"contact.h"
typedef struct al
{
    char name[10];
    unsigned int number;
}al;
void menu()
{
    printf("*********************************************************\n");
    printf("******************   0.exit    **************************\n");
    printf("******************   1.add     **************************\n");
    printf("******************   2.del     **************************\n");
    printf("******************   3.search  **************************\n");
    printf("*********************************************************\n");
    
}
int main()
{
    al contact[1000] = { 0 };
    int num1;
    
    
    do
    {
        menu();
        scanf("%d", &num1);
        switch (num1)
        {
        case 0:
            
            break;
        case 1:
            function(num1, &contact[0]);
            break;
        case 2:
            function(num1, &contact[0]);
            break;
        case 3:
            function(num1, &contact[0]);
            break;
        }
    } while (num1);
    return 0;
}
#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include<stdio.h>
#include<string.h>
void function(int num1,void *contact);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值