C语言大作业——学生通讯录管理系统_c语言通讯录管理系统

其他范文 时间:2020-02-28 04:05:08 收藏本文下载本文
【www.daodoc.com - 其他范文】

C语言大作业——学生通讯录管理系统由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c语言通讯录管理系统”。

#include #include //#define NULL 0 #define LEN sizeof(struct meage)

struct meage

//定义结构体

{

char name[15];

char number[15];

char phone[15];

char qq[13];

char addr[25];

struct meage *next;

//指向下一数据

};

int n;

void creat()

//建立电话簿

{

int num;char choice[5]={'2'};

FILE *fp;

struct meage *head;

struct meage *p,*q;

n = 0;

p = q =(struct meage *)malloc(LEN);

fp=fopen(“通讯录1.txt”,“wb”);

system(“cls”);

printf(“n请输入姓名:”);

scanf(“%s”,p->name);

printf(“n请输入电话号码:”);

scanf(“%s”,p->phone);

printf(“n请输入学号:”);

scanf(“%s”,p->number);

printf(“n请输入QQ:”);

scanf(“%s”,p->qq);

printf(“n请输入住址:”);

scanf(“%s”,p->addr);

fwrite(p,LEN,1,fp);

fclose(fp);

head = 0;

num = 1;

while(num!=0)

{

n = n+1;

if(n==1)head = p;

else q->next = p;

q = p;

p =(struct meage *)malloc(LEN);

//分配存储区

while(choice[0]!='1' && choice[0]!='0')

//判断是否继续

{

printf(“n1 继续输入n 0 返回n”);

printf(“请选择操作:”);

scanf(“%s”,choice);

}

switch(choice[0])

{

case '1':

{

fp=fopen(“通讯录1.txt”,“rb”);

system(“cls”);

printf(“n请输入姓名:”);

scanf(“%s”,p->name);

printf(“n请输入电话号码:”);

scanf(“%s”,p->phone);

printf(“n请输入学号:”);

scanf(“%s”,p->number);

printf(“n请输入QQ:”);

scanf(“%s”,p->qq);

printf(“n请输入住址:”);

scanf(“%s”,p->addr);

fwrite(p,LEN,1,fp);

fclose(fp);

choice[0] = '2';

}

continue;

case '0': num = 0;

system(“cls”);

}

}

q->next = 0;}

void add()

//添加通讯录 {

int num;char choice[5]={'2'};

FILE *fp;

struct meage *head;

struct meage *p,*q;

n = 0;

p = q =(struct meage *)malloc(LEN);

fp=fopen(“通讯录1.txt”,“ab”);

system(“cls”);

printf(“n请输入姓名:”);

scanf(“%s”,p->name);

printf(“n请输入电话号码:”);

scanf(“%s”,p->phone);

printf(“n请输入学号:”);

scanf(“%s”,p->number);

printf(“n请输入QQ:”);

scanf(“%s”,p->qq);

printf(“n请输入住址:”);

scanf(“%s”,p->addr);

fwrite(p,LEN,1,fp);

fclose(fp);

head = 0;

num = 1;

while(num!=0)

{

n = n+1;

if(n==1)head = p;

else q->next = p;

q = p;

p =(struct meage *)malloc(LEN);

while(choice[0]!='1' && choice[0]!='0')

否继续

{

printf(“n1 继续输入n 0 返回n”);

printf(“请选择操作:”);

scanf(“%s”,choice);

}

//分配空间 //输入内容

//分配空间

//判断是

switch(choice[0])

{

case '1':

{

fp=fopen(“通讯录1.txt”,“rb”);

system(“cls”);

printf(“n请输入姓名:”);

scanf(“%s”,p->name);

printf(“n请输入电话号码:”);

scanf(“%s”,p->phone);

printf(“n请输入学号:”);

scanf(“%s”,p->number);

printf(“n请输入QQ:”);

scanf(“%s”,p->qq);

printf(“n请输入住址:”);

scanf(“%s”,p->addr);

fwrite(p,LEN,1,fp);

fclose(fp);

choice[0] = '2';

}

continue;

case '0': num = 0;

system(“cls”);

}

}

q->next = 0;}

void findname(struct meage * fphead)

{

struct meage *p;

int a = 0;

char findname[20];

system(“cls”);

printf(“请输入要查找的姓名:n”);

scanf(“%s”,findname);

for(p=fphead->next;p!=NULL;p=p->next)

{

if(strcmp(p->name,findname)==0)

{

//按姓名查找

printf(“姓名

电话号码

学号

QQ

住址n”);

printf(“%-15s %-15s %-15s %-13s %-25sn”,p->name,p->phone,p->number,p->qq,p->addr);

a = 1;

}

}

if(a!= 1)

printf(“无此通讯录!n”);

} void findphone(struct meage * fphead)

//按电话查找

{

struct meage *p;

int a = 0;

char findphone[15];

system(“cls”);

printf(“请输入要查找的电话:n”);

scanf(“%s”,findphone);

for(p=fphead->next;p!=NULL;p=p->next)

{

if(strcmp(p->phone,findphone)==0)

{

printf(“姓名

电话号码

学号

住址n”);

printf(“%-15s %-15s %-15s %-13s %-25sn”,p->name,p->phone,p->number,p->qq,p->addr);

a = 1;

}

}

if(a!= 1)

printf(“无此通讯录!n”);

}

void findnumber(struct meage * fphead)

//按学号查找

{

struct meage *p;

int a = 0;

char findnumber[15];

system(“cls”);

QQ

printf(“请键入要查找的学生学号:n”);

scanf(“%s”,findnumber);

for(p=fphead->next;p!=NULL;p=p->next)

{

if(strcmp(p->number,findnumber)==0)

{

printf(“姓名

电话号码

学号

QQ

住址n”);

printf(“%-15s %-15s %-15s %-13s %-25sn”,p->name,p->phone,p->number,p->qq,p->addr);

a = 1;

}

}

if(a!= 1)

printf(“无此通讯录!n”);

}

void modify(struct meage * fphead)

//修改记录

{

FILE *fp;

struct meage *p,*q;

int a = 0;

char findname[15];

system(“cls”);

printf(“请键入要查找的姓名:n”);

scanf(“%s”,findname);

for(p=fphead->next;p!=NULL;p=p->next)

{

if(strcmp(p->name,findname)==0)

{

printf(“姓名

电话号码

学号

QQ

住址n”);

printf(“%-15s %-15s %-15s %-13s %-25snnnn”,p->name,p->phone,p->number,p->qq,p->addr);

printf(“n请键入新姓名:”);

scanf(“%s”,p->name);

printf(“n请键入新电话号码:”);

scanf(“%s”,p->phone);

printf(“n请键入新学号:”);

scanf(“%s”,p->number);

printf(“n请键入新QQ:”);

scanf(“%s”,p->qq);

printf(“n请键入新住址:”);

scanf(“%s”,p->addr);

fp = fopen(“通讯录2.txt”,“wb”);

q = fphead->next;

//P为链表头指针

while(q!=0)

{

fwrite(q,LEN,1,fp);

if(q->next!=0)

q = q->next;

else

q = 0;

}

fclose(fp);

unlink(“通讯录1.txt”);

//用新文件覆盖原文件

rename(“通讯录2.txt”, “通讯录1.txt”);

printf(“修改成功!”);

a = 1;

}

}

if(a!= 1)

printf(“无此通讯录!n”);

}

void del(struct meage * fphead)

//删除记录

{

FILE *fp,*fq;

struct meage *p,*q,*r;

char sname[15];

p = q =(struct meage *)malloc(LEN);

p = fphead;

system(“cls”);

fp = fopen(“通讯录1.txt”,“rb”);

fq = fopen(“通讯录2.txt”,“wb”);

printf(“请输入欲删除记录的姓名:”);

scanf(“%s”,sname);

while(strcmp(p->name,sname)!=0 && p->next!=0)//查找节点并删除该节点

{

q = p;

p = p->next;

}

if(strcmp(p->name,sname)==0)

{

if(p==fphead)

fphead = p->next;

else

{

q->next = p->next;

}

r = fphead->next;

//r为链表头指针

while(r!=0)

{

fwrite(r,LEN,1,fq);

if(r->next!=0)

r = r->next;

else

r = 0;

}

printf(“删除成功!”);

}

else

{

printf(“无此通讯录!”);

}

fclose(fp);

fclose(fq);

unlink(“通讯录1.txt”);

//用新文件覆盖原文件

rename(“通讯录2.txt”, “通讯录1.txt”);

}

struct meage * open(void)

//打开文件,载入链表

{

FILE *fp;

struct meage *p=NULL,*q=NULL,*temp=NULL,*fphead=NULL;

fp=fopen(“通讯录1.txt”,“rb”);

fphead=(struct meage *)malloc(LEN);

//分配空间

temp = q = fphead;

while(!feof(fp))

//循环读取,载入链表

{

p=(struct meage *)malloc(LEN);

temp=q;

q->next=p;

q=p;

fread(p,LEN,1,fp);

}

temp->next=NULL;

fclose(fp);

return(fphead);

//返回链表头指针

}

void print()

//显示通讯录

{

struct meage *p;

FILE *fp;

system(“cls”);

if((fp=fopen(“通讯录1.txt”,“rb”))!=NULL)

{

printf(“姓名

电话号码

学号

住址n”);

p =(struct meage *)malloc(LEN);

//分配空间

while(!feof(fp))

{

fread(p,LEN,1,fp);

printf(“%-15s %-15s %-15s %-13s %-25sn”,p->name,p->phone,p->number,p->qq,p->addr);

}

fclose(fp);

}

else

{

printf(“未建立通讯录!”);

} }

void main()

//主函数 {

FILE * fp;

struct meage * fphead;

int begin = 1,f;

char choice[5];

QQ

while(begin == 1)

{

printf(“tt>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>n”);

printf(“tttt欢迎使用学生通讯录n”);

printf(“tt

printf(”ttt*主窗口菜单*nn“);

printf(”ttt1:显示通讯录中所有记录;nn“);

printf(”ttt2:建立新通讯录;nn“);

printf(”ttt3:添加新记录;nn“);

printf(”ttt4:查询通讯录中的记录;nn“);

printf(”ttt5:修改通讯录中的记录;nn“);

printf(”ttt6:删除通讯录中的记录;nn“);

printf(”ttt0:退出通讯录nn“);

printf(”请选择操作:“);

scanf(”%s“,choice);

switch(choice[0])

{

case '1':

{

print();

printf(”按任意键返回主菜单!n“);

getch();

system(”cls“);

}

continue;

case '2':

{

creat();

}

continue;

case '3':

{

add();

}

continue;

case '4':

{

if((fp = fopen(”通讯录1.txt“,”rb“))!= NULL)

{

fclose(fp);

system(”cls“);

printf(”1按姓名查询;n2按电话查询;n3按学号查询;n“);

printf(”请输入查询方式:“);

scanf(”%d“,&f);

if(f==1)

{

fphead = open();

findname(fphead);

}

if(f==2)

{

fphead = open();

findphone(fphead);

}

else if(f==3)

{

fphead = open();

findnumber(fphead);

}

}

else

{

system(”cls“);

printf(”未建立通讯录!“);

}

printf(”按任意键返回主菜单!n“);

getch();

system(”cls“);

}

continue;

case '5':

{

if((fp = fopen(”通讯录1.txt“,”rb“))!= NULL)

{

fclose(fp);

fphead = open();

modify(fphead);

}

else

{

system(”cls“);

printf(”未建立通讯录!“);

}

printf(”按任意键返回主菜单!n“);

getch();

system(”cls“);

}continue;

case '6':

{

if((fp = fopen(”通讯录1.txt“,”rb“))!= NULL)

{

fclose(fp);

fphead = open();

del(fphead);

}

else

{

system(”cls“);

printf(”未建立通讯录!“);

}

printf(”按任意键返回主菜单!n“);

getch();

system(”cls“);

}

continue;

case '0': exit(0);

default:

{

system(”cls“);

printf(”输入错误,按任意键返回主菜单!n“);

getch();

system(”cls“);

}

}

}

system(”pause");}

学生通讯录管理系统

“学生通讯信息记录系统”的设计与实现一、设计要求1.问题的描述“学生通讯信息记录系统”是为了实现快速的对学生信息进行录入、删除、查找、显示。各个功能靠函数实现。 2......

C语言通讯录管理系统

#include #include #include struct record{ charnum[12]; char name[10]; char birthday[10]; char post[10]; char phone[15]; }data[100]; intmenu_select( ); intcreat......

C语言程序设计学生通讯录管理系统

#include "stdio.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "stdlib.h" #define null 0 struct record { char name[20]; char p......

通讯录管理系统

摘 要为了人们对他人信息的记忆方便而设计,开发的一套“通讯录管理系统“软件。 通过该题目的设计过程,可以培养学生结构化程序设计的思想,加深对高级语言基本语言要素和控制结......

通讯录管理系统

淮北师范大学软件系列课程设计通讯录管理系统学院计算机科学与技术学院学 生 姓 名陈 文 超学号20081201011指导教师姓名陈 美 荣 2010年 06月 20日 目 录 摘 要 ...............

下载C语言大作业——学生通讯录管理系统word格式文档
下载C语言大作业——学生通讯录管理系统.doc
将本文档下载到自己电脑,方便修改和收藏。
点此处下载文档

文档为doc格式

热门文章
点击下载本文