I need to create this program in C and before i accepted simply an ID and compared the ID in the List with the given ID, which worked fine. However, i need to compare the name of a city instead of the id. How does that work in C?
Old code:
// Finds a city in a given CityList with an integer id.
City *findCity(CityList *cl, int id)
{
int i;
City *s = NULL;
for (i = 0; i < cl->count; i++)
if (cl->city[i]->cityId == id))
{
s = cl->city[i];
}
return s;
}
So this worked just fine, however, i need to find a city by using an string (char *) to check if its in the list. Any ideas?
My approach:
City *findCity(CityList *cl, char *name)
{
int i;
City *s = NULL;
for (i = 0; i < cl->count; i++)
if (cl->city[i]->cityId == name))
{
s = cl->city[i];
}
return s;
}
Which isn't working as i saw that you can't use == in C.