代码语言:c复制
#include <cs50.h>
#include <stdio.h>
int main(void)
{
string strings[] = {"battleship", "boot", "cannon", "iron", "thimble", "top hat"};
string s = get_string("String: ");
for (int i = 0; i < 6; i )
{
if (strings[i] == s)
{
printf("Foundn");
return 0;
}
}
printf("Not Foundn");
return 1;
}
代码语言:c复制#include <cs50.h>
#include <stdio.h>
#include <string.h>
typedef struct
{
string name;
string number;
}
person;
int main(void)
{
person people[3];
people[0].name = "Carter";
people[0].number = " 1-617-495-1000";
people[1].name = "David";
people[1].number = " 1-617-495-1000";
people[2].name = "John";
people[2].number = " 1-949-468-2750";
string name = get_string("Name: ");
for (int i = 0; i < 3; i )
{
if (strcmp(people[i].name, name) == 0)
{
printf("Found %sn", people[i].number);
return 0;
}
}
printf("Not Foundn");
return 1;
}