I am writing a program that takes information from a .txt file. On each line of the file are the names of two cities and the distance between them (in miles). I want the user to be able to type in a city of departure and a destination, and have the program find the shortest route and the distance.
e.g. if the text file reads:
Code:
New York Orlando 932
California Orlando 740
and the user types in:
Code:
City of Departure: California
Destination: New York
I want the program to find a path between the two cities. However, to do this I will need to store some information for each city and look it up. I originally planned to use this structure:
Code:
e.g. for Orlando...
char dep[] = Orlando;
char dest1[] = California;
int dist1 = 740;
char dest2[] = New York;
int dist2 = 932;
But this means that to look up a city I would need to compare the city name (string) the user types in, with every single 'char dep[]' string. This could take a long time to look up If I have a large amount of cities in the .txt file.
A friend suggested I use a hash table to store the information, but after looking into this it seems complicated to use to look up words (I'm still a beginner with C).
Can anyone suggest any other methods to me?
Or even a simplified explanation of how hash tables work would be great