c语言结构体学习时写的小代码
来源:互联网 发布:盛势网络剧视频第四集 编辑:程序博客网 时间:2024/06/07 09:33
#include <stdio.h>
#include <string.h>
struct time
{
char riqi[20];
};
struct student
{
char number[20];
char name[20];
struct time t;
char dizhi[20];
char haoma[20];
}stu[20];
int i=0;
void charu()
{
printf("请输入编号,名字,地址,联系电话,出生年月日\n");
scanf("%s%s%s%s%s",stu[i].number,stu[i].name,stu[i].dizhi,stu[i].haoma,stu[i].t.riqi);
i++;
}
void chazhao()
{
int n,j=0;
char str[20];
printf("请输入要查找的姓名/出生日期/电话\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if((strcmp(stu[n].name,str)==0)||(strcmp(stu[n].t.riqi,str)==0)||(strcmp(stu[n].haoma,str)==0))
{
printf("%s %s %s %s %s\n",stu[n].number,stu[n].name,stu[n].dizhi,stu[n].haoma,stu[n].t.riqi);
j=1;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
void shanchu()
{
int n=0,j=0;
char str[20];
printf("请输入要删除的姓名/出生日期/电话\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if((strcmp(stu[n].name,str)==0)||(strcmp(stu[n].t.riqi,str)==0)||(strcmp(stu[n].haoma,str)==0))
{
strcpy(stu[n].number," ");
strcpy(stu[n].name," ");
strcpy(stu[n].dizhi," ");
strcpy(stu[n].haoma," ");
strcpy(stu[n].t.riqi," ");
j=1;
i--;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
void xiugai()
{
int n=0,j=0;
char str[20];
printf("请输入要修改的人的姓名\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if(strcmp(stu[n].name,str)==0)
{
printf("请输入修改信息,编号,名字,地址,号码,出生年月\n");
scanf("%s%s%s%s%s",stu[n].number,stu[n].name,stu[n].dizhi,stu[n].haoma,stu[n].t.riqi);
j=1;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
int main()
{
int n;
int k;
while(1)
{
printf("0退出 1查找 2删除 3修改 4插入\n");
scanf("%d",&n);
switch(n)
{
case 0: break;
case 1: chazhao();break;
case 2: shanchu();break;
case 3: xiugai();break;
case 4: charu();break;
default:printf("没有这数字,请再次输入\n");break;
}
}
return 0;
}
#include <string.h>
struct time
{
char riqi[20];
};
struct student
{
char number[20];
char name[20];
struct time t;
char dizhi[20];
char haoma[20];
}stu[20];
int i=0;
void charu()
{
printf("请输入编号,名字,地址,联系电话,出生年月日\n");
scanf("%s%s%s%s%s",stu[i].number,stu[i].name,stu[i].dizhi,stu[i].haoma,stu[i].t.riqi);
i++;
}
void chazhao()
{
int n,j=0;
char str[20];
printf("请输入要查找的姓名/出生日期/电话\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if((strcmp(stu[n].name,str)==0)||(strcmp(stu[n].t.riqi,str)==0)||(strcmp(stu[n].haoma,str)==0))
{
printf("%s %s %s %s %s\n",stu[n].number,stu[n].name,stu[n].dizhi,stu[n].haoma,stu[n].t.riqi);
j=1;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
void shanchu()
{
int n=0,j=0;
char str[20];
printf("请输入要删除的姓名/出生日期/电话\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if((strcmp(stu[n].name,str)==0)||(strcmp(stu[n].t.riqi,str)==0)||(strcmp(stu[n].haoma,str)==0))
{
strcpy(stu[n].number," ");
strcpy(stu[n].name," ");
strcpy(stu[n].dizhi," ");
strcpy(stu[n].haoma," ");
strcpy(stu[n].t.riqi," ");
j=1;
i--;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
void xiugai()
{
int n=0,j=0;
char str[20];
printf("请输入要修改的人的姓名\n");
scanf("%s",str);
for(n=0;n<i;n++)
{
if(strcmp(stu[n].name,str)==0)
{
printf("请输入修改信息,编号,名字,地址,号码,出生年月\n");
scanf("%s%s%s%s%s",stu[n].number,stu[n].name,stu[n].dizhi,stu[n].haoma,stu[n].t.riqi);
j=1;
}
}
if(j!=1)
{
printf("没有这个人\n");
}
}
int main()
{
int n;
int k;
while(1)
{
printf("0退出 1查找 2删除 3修改 4插入\n");
scanf("%d",&n);
switch(n)
{
case 0: break;
case 1: chazhao();break;
case 2: shanchu();break;
case 3: xiugai();break;
case 4: charu();break;
default:printf("没有这数字,请再次输入\n");break;
}
}
return 0;
}
阅读全文
0 0
- c语言结构体学习时写的小代码
- C语言学习过程中写的小程序
- C语言结构体的学习
- c语言结构体的学习
- c语言写的一些小程序
- C语言写的扫雷小程序
- c语言写的一些小程序
- 回顾曾经写过的c语言小代码(一)
- 学习C语言结构体
- C语言-结构体学习
- C语言学习-结构体
- C语言中结构体小技巧
- C语言之结构体小总结
- C语言小问题---结构体
- 一段C语言写的病毒代码
- c语言代码运行时的内存分布结构
- 用c/c++语言写的一个小的“爬虫”程序学习过程总结
- C语言的分支结构的学习
- iOS 最简单解决事件冲突的思路,深入浅出cancelsTouchesInView属性
- OrientDB社区版Linux分布式部署失败
- 使聊天机器人具有个性
- 强化学习及Python代码示例
- HTML-标签语义化
- c语言结构体学习时写的小代码
- 对指令集的一点理解
- 2017 CBDS第四届中国国际大数据大会9月26日北京召开
- Lintcode C++代码
- 如何用Tensorflow训练模型成pb文件和和如何加载已经训练好的模型文件
- WPF面试知识要点
- 使用SOCKET实现TCP/IP协议的通讯
- ORA-29857:表空间中存在域索引和/或次级对象
- myeclipse中如何修改Servlet模板