用C语言编写一个手机电话本程序

用C语言编写一个手机电话本程序,第1张

#include <stdio.h>#include <stdlib.h>#include <string.h>#define szSTR 64 #define fileDB "c:\\contact.txt" struct CONTACT { char name[szSTR]/*姓名*/ char unit[szSTR]/*工作单位*/ char tele[szSTR]/*电话*/ char mail[szSTR]/*mail*/ }typedef struct CONTACT CON#define BNAME 1 #define BUNIT 2 #define BTELE 4 #define BMAIL 8 #define BFULL 0xFF int OPER[5] = void input(CON * s, int mask) { if(mask &BNAME) if(mask &BUNIT) if(mask &BTELE) if(mask &BMAIL) }/*end input*/ void show (int id, CON * s) { if(!s) return if(id) printf("%d\t%s\t%s\t%s\t%s\n", id, s->name , s->unit , s->tele , s->mail )else printf("%s%s%s%s\n", s->name , s->unit , s->tele , s->mail )/*end if*/ }/*end show*/ void regist(void) { CON sFILE * f = 0input(&s, BFULL)f = fopen(fileDB, "ab")fwrite(&s,sizeof(s),1,f)fclose(f)printf("资料已保存!\n")}/*end regist*/ int browse(char * key, fpos_t * p, CON * s) { FILE * f =0int i = 0, r = 0CON tchar * a = 0, * b = 0fpos_t q if(!s) return 0f = fopen(fileDB, "rb")if(!f) { printf("数据库暂无记录\n")return 0}/*end if*/ printf("编号\t姓名\t单位\t电话\t电邮\n")printf("------------------------------------------------\n")while(!feof(f)) { fgetpos(f, &q)r = fread(&t, sizeof(t), 1, f)if(r<1)breakif(t.name[0]==0) continueif(key) { a = strstr(t.name , key)b = strstr(t.tele , key)if(a == 0 &&b == 0) continue}/*end if*/ if(p) *p = qif(s) memcpy(s, &t, sizeof(t))i++show(i, &t)}/*end while*/ fclose(f)printf("------------------------------------------------\n")return i}/*end browse*/ fpos_t query(CON * s) { char key[szSTR]=""fpos_t p = 0int r = 0printf("请输入姓名或者电话号码:")scanf("%s", key)r = browse(key, &p, s)return r?p:-1}/*end query*/ void clear(void) { FILE * f = 0CON sfpos_t p = query(&s)if(p<0) returnf = fopen(fileDB, "rb+")fsetpos(f, &p)memset(&s, 0, sizeof(s))fwrite(&s, sizeof(s),1, f)fclose(f)printf("记录已删除!\n")}/*end clear*/ void modify(void) { FILE * f = 0CON sint cmd = 0fpos_t p = query(&s)if(p<0) returnf = fopen(fileDB, "rb+")fsetpos(f, &p)for() { show(0, &s)printf("请选择:1-姓名2-工作单位3-电话4-电邮5-保存并退出6-放弃修改并退出\n")scanf("%d", &cmd)switch(cmd) { case 1: case 2: case 3: case 4: input(&s, OPER[cmd])breakcase 5: fsetpos(f, &p)fwrite(&s, sizeof(s), 1, f)case 6: fclose(f)returndefault: printf("错误的 *** 作,请重新输入。\n")}/*end case*/ }/*mext*/ }/*end clear*/ int main(void) { int cmd = 0CON sfor() { printf("欢迎使用通信簿!请选择:1-添加2-查询3-删除4-修改5-全部输出0-退出\n")scanf("%d", &cmd)switch(cmd) { case 0: return 0case 1: regist()breakcase 2: query(&s)breakcase 3: clear()breakcase 4: modify()breakcase 5: browse(0, 0, &s)break}//end case } return 0}

记得采纳啊

简单通讯录管理程序,代码如下:#include

<stdio.h>

#include

<string.h>

#include

<stdlib.h>

typedef

struct

student

*ST

struct

student

{

char

stN[20]

char

stVal[128]

char

stNo[10]

char

stTel[12]

ST

next

}

ST

head

=

NULL

int

ShowNode()

{

char

no[20]

=

{0}

ST

t

printf("输入姓名:")

scanf("%s",

no)

for

(t

=

head

t

t

=

t->next)

{

if

(!memcmp(t->stN,

no,

strlen(no)))

{

printf("姓名:%s,

地址:%s

邮编:%s

电话:%s\n",

t->stN,

t->stVal,

t->stNo,

t->stTel)

return

0

}

}

printf("无此人信息\n")

return

0

}

int

ChangeNode()

{

char

no[20]

ST

t

printf("输入姓名:")

scanf("%s",

no)

for

(t

=

head

t

t

=

t->next)

{

if

(!memcmp(t->stN,

no,

strlen(no)))

{

printf("输入新的记录:\n")

printf("地址:")

scanf("%s",

t->stVal)

printf("邮编:")

scanf("%s",

t->stNo)

printf("英语成绩:")

scanf("%s",

t->stTel)

return

0

}

}

printf("无此人信息\n")

return

0

}

int

InsertNode()

{

ST

t

t

=

(ST)malloc(sizeof

*t)

printf("输入姓名:")

scanf("%s",

t->stN)

printf("输入地址:")

scanf("%s",

t->stVal)

printf("输入邮编:")

scanf("%s",

t->stNo)

printf("输入电话:")

scanf("%s",

t->stTel)

t->next

=

head

head

=

t

return

0

}

int

DelNode()

{

ST

x,

y

char

no[20]

=

{0}

printf("输入姓名:")

scanf("%s",

no)

for

(x

=

y

=

head

x

y

=

x,

x

=

x->next)

{

if

(!memcmp(x->stN,

no,

strlen(no)))

{

if

(x

==y)

{

x

=

head

=

head->next

y->next

=

NULL

free(y)

return

0

}

else

{

y->next

=

x->next

x->next

=

NULL

free(x)

return

0

}

}

}

printf("无此学生\n")

return

0

}

int

main(void)

{

int

i

while(1)

{

printf("查询记录:1\n"

"更改记录:2\n"

"插入记录:3\n"

"删除记录:4\n"

"退出:5\n")

scanf("%d",

&i)

if

(1==i)

{

ShowNode()

}

else

if(2==i)

{

ChangeNode()

}

else

if(3==i)

{

InsertNode()

}

else

if(4==i)

{

DelNode()

}

else

if(5==i)

{

break

}

else

{

printf("输入错误!请重新输入!\n")

continue

}

}

return

0

}

#include#include#include#defineM500structMan//定义结构体{charName[8]//名字charDepart[20]//工作单位charQQ[10]//QQ号码charEmail[30]//邮箱}voidtext()//相当于主函数voidtext1()//菜单输出chartext2()//开始的版权信息输出intDelete(ManMan[],intSize)//删除信息voidDisplay(Manman[])//显示所有记录voidgetch()intInsert(ManMan[],intSize)//插入模块voidModify(ManMan[],intSize)//修改模块intS_asname(ManMan[],intSize,intn)//查找信息voidS_asqq(ManMan[],intSize)//按QQ查找模块intSave(ManMan[],intSize)//把数据写入文件intScan(ManMan[])//从文本中读取数据voidmain()//主函数{text()//(这边纯属蛋疼,最多加长系统运行时间)}voidtext()//相当于主函数{Manman[M]//500人的结构体数组charcontrol=0//菜单选择控制变量intsize=0//保存当前已有的记录if(text2())//这边可不要if,直接调用text2,显示版权信息。{size=Scan(man)//判断文件是否存在while(1)//菜单生成{text1()//菜单显示scanf(


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11579733.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存