C语言-指针练习-12

题目:

信息查询

从键盘中输入姓名和电话号码,以"#"结束,编程实现输入姓名,查询电话号码的功能。

源代码:

#include <stdio.h>
#include <string.h>
#define MAX 10
struct information
{
    char name[20];
    char Telephone_number[20];
};
void insert_information(struct information * infor,int max);
int select_information(struct information * infor,int max,char * select_name);
int main()
{
    struct information infor[MAX];
    char select_name[20];
    int select_location;
    insert_information(infor,MAX);
    printf("\n请输入你要查询的姓名: ");
    scanf("%s",select_name);
    select_location = select_information(infor,MAX,select_name);
    if( select_location != 0)
    {
        printf("姓名: %s\n电话号码: %s\n",infor[select_location-1].name,infor[select_location-1].Telephone_number);
    }
    else    printf("查询失败\n");
    return 0;
}
void insert_information(struct information * infor,int max)
{
    printf("请输入要插入的信息(输入#停止输入): \n");
    for(int i = 0;i < max;i++)
    {
        scanf("%s",infor[i].name);
        if(infor[i].name[0] == '#') break;
        scanf("%s",infor[i].Telephone_number);
    }
}
int select_information(struct information * infor,int max,char * select_name)
{
    for(int i = 0;i < max;i++)
    {
        if(!strcmp(select_name,infor[i].name))  return i+1;
    }
    return 0;
}

演示效果:


如果朋友你感觉文章的内容对你有帮助,可以点赞关注文章和专栏以及关注我哈,嘿嘿嘿我会定期更新文章的,谢谢朋友你的支持哈

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是小天才哦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值