日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言通讯录人数显示,c语言实现通讯录

發布時間:2023/12/31 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言通讯录人数显示,c语言实现通讯录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#include#define MAXN 20

#define MAXS 5

#define MAXA 15

static count = 1;

static int peocnt = 1;

typedef struct

{

char name[MAXN];

char sex[MAXS];

char addr[MAXA];

char num[11];

int age;

}stu;

enum optin//枚舉類型(用在main函數的switch分支語句中,免得寫出挫挫的case 1之類的代碼)

{

EXIT,//0

ADD,//1

DEL,//2

SEARCH,//3

MODIFY,//4

SHOW,//5

EMPTY,//6

};

void menu()

{

printf("*************************************************************\n");

printf("****** 1增加通訊錄人數 2刪除通訊錄人數 *******\n");

printf("****** 3查找通訊錄 4修改通訊錄 *******\n");

printf("****** 5顯示通訊錄 6清空通訊錄 *******\n");

printf("****** 0退出通訊錄 *******\n");

printf("*************************************************************\n");

}

void Add(stu* p)

{

if (count > peocnt)

{

stu *p1 = realloc(p,count*sizeof(stu));

if (p1 != NULL)

p = p1;

printf("增容成功!\n");

}

printf("請輸入姓名:\n");

scanf("%s", p[count-1].name);

printf("請輸入性別:\n");

scanf("%s", p[count - 1].sex);

printf("請輸入地址:\n");

scanf("%s", p[count - 1].addr);

printf("請輸入電話:\n");

scanf("%s", p[count - 1].num);

printf("請輸入年齡:\n");

scanf("%d", &p[count - 1].age);

count++;

}

void Del(stu* p)

{

int i = 0;

char tmp[MAXN] = { 0 };

printf("請輸入你要刪除的名字:\n");

scanf("%s", tmp);

for (i = 0; i < count-1; i++)

{

if (strcmp(tmp, p[i].name) == 0)

{

strcpy(p[i].name, p[count - 2].name);

strcpy(p[i].sex, p[count - 2].sex);

strcpy(p[i].addr, p[count - 2].addr);

strcpy(p[i].num, p[count - 2].num);

p[i].age = p[count - 2].age;

count--;

return;

}

}

if (i == count-1)

printf("查無此人\n");

}

void Search(stu* p)

{

char tmp[MAXN] = { 0 };

int i = 0;

printf("請輸入你要查找的人:\n");

scanf("%s", tmp);

for (i = 0; i < count-1; i++)

{

if (strcmp(tmp, p[i].name) == 0)

{

printf("姓名 年齡 性別 地址 電話\n");

printf("%5s %5d %5s %5s %5s", p[i].name, p[i].age, p[i].sex, p[i].addr, p[i].num);

printf("\n");

break;

}

}

if (i == count-1)

printf("查無此人\n");

}

void Modify(stu* p)

{

int i = 0;

char tmp[MAXN] = { 0 };

printf("請輸入你要修改的人名;\n");

scanf("%s", tmp);

for (i = 0; i < count-1; i++)

{

if (strcmp(tmp, p[i].name) == 0)

{

printf("請輸入姓名:\n");

scanf("%s", p[i].name);

printf("請輸入性別:\n");

scanf("%s", p[i].sex);

printf("請輸入地址:\n");

scanf("%s", p[i].addr);

printf("請輸入電話:\n");

scanf("%s", p[i].num);

printf("請輸入年齡:\n");

scanf("%d", &p[i].age);

}

}

if (i == count-1)

printf("查無此人\n");

}

void Show(stu* p)

{

int i = 0;

printf("姓名 年齡 性別 地址 電話\n");

for (i = 0; i < count-1; i++)

{

printf("%5s %5d %5s %5s %5s", p[i].name, p[i].age, p[i].sex, p[i].addr, p[i].num);

printf("\n");

}

}

void Empty(stu* p)

{

count = 0;

}

int main()

{

int input = 1;

stu *p = NULL;

stu *p1 = malloc(peocnt*sizeof(stu));

if (p1 != NULL)

p = p1;

else

perror("malloc:\n");

memset(p, 0, peocnt*sizeof(stu));

while (input)

{

menu();

printf("請輸入選項>");

scanf("%d", &input);

switch (input)

{

case ADD:

Add(p);

break;

case DEL:

Del(p);

break;

case SEARCH:

Search(p);

break;

case MODIFY:

Modify(p);

break;

case SHOW:

Show(p);

break;

case EMPTY:

Empty(p);

break;

case EXIT:

break;

default:

printf("選擇有誤!\n");

break;

}

}

system("pause");

return 0;

}

總結

以上是生活随笔為你收集整理的c语言通讯录人数显示,c语言实现通讯录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。