资源简介
功能:添加,删除,查找,全部输出。
添加时自动保存到文件,
查找、全部输出时从文件中读取;
复制粘贴即可运行!绝对好用
代码片段和文件信息
#include
#include
#include
struct inf
{
char num[20];
char name[12];
char tel[20];
struct inf *next;
};
int count()
{
FILE *fp;
int nx;
fp=fopen(“通讯录.txt““r“);
fseek(fp 0L SEEK_END);
n = ftell(fp);//n是文件的字节总数
fseek(fp 0L SEEK_SET);
x=n/56;
return x;
}
int select()/*******************************选择***************************************/
{
int num;
printf(“\n请选择\n“);
scanf(“%d“&num);
printf(“\n“);
return num;
}
struct inf *create()/*******************************创建***************************************/
{
struct inf *head*temp*tail;
temp=(struct inf*)malloc(sizeof(struct inf));
temp->next=0;
head=tail=temp;
return head;
}
void add(struct inf *headstruct inf *p) /*******************************添加***************************************/
{
struct inf *p1*p2;
p1=head;
p2=p1->next;
while(p2!=0&&p2->numnum)
{
p1=p2;
p2=p2->next ;
}
p1->next=p;
p->next=p2;
}
struct inf *find(struct inf *head)/*******************************查找***************************************/
{
struct inf *p1;
FILE *fp;
char n[12];
int ix;
fp=fopen(“通讯录.txt““r“);
x=count();
printf(“输入姓名:\n“);
scanf(“%s“&n);
for(i=0;i {
p1=(struct inf*)malloc(sizeof(struct inf));
fseek(fpi*sizeof(struct inf)0);
fread(p1sizeof(struct inf)1fp);
if(strcmp(p1->namen)==0)
{
return p1;
}
}
if(i==x)
{
return 0;
}
}
void print(struct inf *p)/*******************************单个输出***************************************/
{
printf(“%s:\t姓名:%s\t电话:%s\n\n“p->nump->name p->tel);
}
void printall(struct inf *head)/*******************************全部输出***************************************/
{
struct inf *p;
p=head->next;
while(p!=NULL)
{
printf(“%s:\t姓名:%s\t电话:%s\n“p->nump->namep->tel);
p=p->next;
}
}
void del(struct inf *head)/*******************************删除***************************************/
{
struct inf *p1*p;
FILE *fp;
char n[12]d;
int ix;
fp=fopen(“通讯录.txt““r“);
x=count();
printf(“输入姓名:\n“);
scanf(“%s“&n);
for(i=0;i {
p1=(struct inf*)malloc(sizeof(struct inf));
fseek(fpi*sizeof(struct inf)0);
fread(p1sizeof(struct inf)1fp);
if(strcmp(p1->namen)==0)
{
break;
}
}
if(i==x)
{
printf(“未找到!\n\n“);
}
else
{
if(i!=-1)
{
printf(“真的要删除吗?(Y/N)\n“);
getchar();
scanf(“%c“&d);
if(d==‘Y‘||d==‘y‘)
{
p=(struct inf*)malloc((x-1)*sizeof(struct inf));
fseek(fp0L0);
fread(psizeof(struct inf)ifp);
fseek(fp(i+1)*sizeof(struct inf)0);
fread(psizeof(struct inf)x-i-1
相关资源
- C语言编程常见问题解答.pdf
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
评论
共有 条评论