c语言结构体学习时写的小代码

#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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值