/* The simplest way I can think of solving this problem (i.e., the brute force method): * 1. enter all cities, with their relative distances, into an "adjacency matrix" * - in this particular case, we have a fully connected (i.e., "complete") graph. * - the number of *unique* possible paths are 8!/2 = 20,160 * 2. the cities are labeled 0 through 7. * - hence the possible paths are different ways to arrange the numbers 0, 1, 2, 3, 4, 5, 6, 7. * 3. construct a nested for-loop (or a recursive function) to walk through each node. * 4. from an arbitrary start to an arbitrary end, mark down the length of the path. * !. but how do you avoid reversed paths? |01234567| = |76543210|... */ #include int main() { FILE *file = fopen("testinput", "r"); if (file == NULL) { perror("main: error opening file."); return 1; } char city1[12]; char city2[12]; int dist = 0; while (fscanf(file, "%s to %s = %d\n", city1, city2, &dist) != EOF) { printf("%s, %s, %d\n", city1, city2, dist); } fclose(file); return 0; }