微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

您能否针对C,cs50中的函数输入实现新类型

如何解决您能否针对C,cs50中的函数输入实现新类型

我当时正在为电话簿编写一个小程序,但我无法为我的函数搜索”工作而使用输入,遇到麻烦的变量是我刚刚创建的“人”女巫类型(2个数组的列表)

给我的问题是当我编译代码时,它说类型人员不是类型,但是我用typedef新建了一个类型。

我不是在寻找优化,这就是为什么我的函数输入中的类型不被接受为var的原因

代码

#include <cs50.h>
#include <stdio.h>
#include <string.h>

// new type for storing list of name and phone numbers.
typedef struct
{
    string name;
    string number;
}
person;

void search(int count,person people[]);

int main(void)
{
    // get the user input for how many person you want
    int person_count = get_int("How many person is there? : ");
    
    // create people and the length of the array
    person people[person_count];

    // make the repertoire for each person on the list 
    for (int i = 0; i < person_count; i++)
    {
        // get user input for each person
        people[i].name = get_string("Your name : ");
        people[i].number = get_string("Your number : ");

        printf("\n");
    }

    search(person_count,people);
}

// new function "search"
void search(int count,person people[])
{
    int repeat = 0;

    // get user input for his search
    string name_search = get_string("Your search : ");

    // iterate for every person on the list 
    for (int j = 0; j < count; j++)
    {
        if (strcmp(people[j].name,name_search) == 0)
        {
            printf("This is the phone number of %s\n",people[j].name);
            printf("%s\n",people[j].number);
            return
        }
    }
    else
    {
        repeat = 1;
    }

    // if not found 
    printf("%s,is not in our repertoire.\n",name_search);

    if (repeat == 1)
    {

        // asking if they want to search it again
        string try_again = get_string("Would you like to search for a other person? (Y/N) : ");

        if (strcmp(try_again,"Yes") == 0 || strcmp(try_again,"yes") == 0 || (int) try_again == 89 || (int) try_again == 121)
        {
            sreach(count,people);
        }
        return
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。