海滩长颈鹿342 2022-05-21 20:43 采纳率: 100%
浏览 40
已结题

不知道哪里出了问题?

设计一个通讯录,里面有名字,微信号和电话号码,下面是我的程序
#include <stdio.h>
#include <string.h>
#define N 3

struct people
{
char name[10];
char weixin[15];
char phone[15];
}p[N];
int main()
{
void input(struct people p[]);
void input(struct people p[]);
struct people *find(struct peope p[],char str[]);
struct people *a;
char str[8];
input (p);
output (p);
printf("input finding name: ");
scanf("%s",str);
a=find(p,str);
if(a==NULL)
printf("not find\n");
else
printf("%-10s%-15d%-15c",a->name,a->weixin,a->phone);
return 0;
}
void input (struct people p[])
{
int i;
for(i=0;i<N;i++)
{
printf("input data of people %d:\n",i+1);
printf("name: ");
scanf("%s",p[i].name);
printf("wexin: ");
scanf("%d",p[i].wexin);
printf("phone: ");
scanf("%c",p[i].phone);
printf("\n");
}
}
void output (struct people p[])
{
int i;
printf("\n name weixin phone\n");
for(i=0;i<N;i++)
{
printf("%-10s%-15d%-15c",p[i].name,p[i].weixin,p[i].phone);
printf("\n");
}
}
struct people * find(struct people p[],char str[])
{
int i;
for(i=0;i<N;i++)
{
if(strcmp(str,p[i].name)==0)
return &p[i];
}
return NULL
}

  • 写回答

1条回答 默认 最新

  • 树下等苹果 2022-05-21 21:51
    关注

    修改好了,

    #include <stdio.h>
    #include <string.h>
    #define N 3
    
    struct people
    {
        char name[10];
        char weixin[15];
        char phone[15];
    }p[N];
    int main()
    {
        void input(struct people p[]);
        void output(struct people p[]);
        struct people* find(struct peope p[], char str[]);
        struct people* a;
        char str[8];
        input(p);
        output(p);
        printf("input finding name: ");
        scanf("%s", str);
        a = find(p, str);
        if (a == NULL)
            printf("not find\n");
        else
            printf("%s %s %s\n", a->name, a->weixin, a->phone);
        return 0;
    }
    void input(struct people p[])
    {
        int i;
        for (i = 0; i < N; i++)
        {
            printf("input data of people %d:\n", i + 1);
            printf("name: ");
            gets(p[i].name,10);
            printf("wexin: ");
            gets(p[i].weixin);
            printf("phone: ");
            gets(p[i].phone);
            printf("\n");
        }
    }
    void output(struct people p[])
    {
        int i;
        printf("\n name weixin phone\n");
        for (i = 0; i < N; i++)
        {
            printf("%s %s %s", p[i].name, p[i].weixin, p[i].phone);
            /*puts(p[i].name);
            puts(p[i].weixin);
            puts(p[i].phone); */
            printf("\n");
        }
    }
    struct people* find(struct people p[], char str[])
    {
        int i;
        for (i = 0; i < N; i++)
        {
            if (strcmp(str, p[i].name) == 0)
                return &p[i];
        }
        return NULL;
    }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月26日
  • 已采纳回答 5月21日
  • 赞助了问题酬金5元 5月21日
  • 修改了问题 5月21日
  • 展开全部

悬赏问题

  • ¥15 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图