问题描述
我当时正在为电话簿编写一个小程序,但我无法为我的函数“搜索”工作而使用输入,遇到麻烦的变量是我刚刚创建的“人”女巫类型(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 (将#修改为@)