src/ManageConnections.c
/*
 * FUNCTION NAME: addConnection
 *
 * DESCRIPTION:
 * Function gets from user names of cities, that create a
 * connection that will be added to the graph. Then, it checks, if cities
 * typed in by the user are already in the graph.
 * Then it calls a proper function that adds a new connection.
 * Which function is called depends on number of cities
 * that are already in the graph.
 */
FUNCTION NAME: addConnection
DESCRIPTION:
Function gets from user names of cities, that create a
connection that will be added to the graph. Then, it checks, if cities
typed in by the user are already in the graph.
Then it calls a proper function that adds a new connection.
Which function is called depends on number of cities
that are already in the graph.
FUNCTION NAME : addConnection DESCRIPTION : Function gets from user names of cities that create a connection that will be added to the graph . Then it checks if cities typed in by the user are already in the graph . Then it calls a proper function that adds a new connection . Which function is called depends on number of cities that are already in the graph .
void addConnection(Graph_t* graph)
{
    char city1[G_CITYS_NAME_LENGTH];
    char city2[G_CITYS_NAME_LENGTH];
    double distance = 0;
    programError_t what_error = NO_ERROR;
    size_t number_of_cities_in_graph = 0;
    do {
        printErrorUsersActions(what_error);
        getCitysName(FIRST_CITY, city1);
        what_error = checkIfNameIsCorrect(city1);
    } while (what_error != NO_ERROR);
    do {
        printErrorUsersActions(what_error);
        getCitysName(SECOND_CITY, city2);
        what_error = checkIfNameIsCorrect(city2);
        if (what_error == NO_ERROR)
            what_error = checkIfNamesAreIdentical(city1, city2);
        if (what_error == NO_ERROR) {
            what_error = checkIfConnectionIsInGraph(graph, city1, city2);
        }
    } while (what_error != NO_ERROR);
    do {
        printErrorUsersActions(what_error);
        getDistanceBetweenCities(&distance);
        what_error = checkIfDistanceIsCorrect(distance);
    } while (what_error != NO_ERROR);
    AdjacencyList_t* adjacency_list;
    for (adjacency_list = graph->head; adjacency_list != NULL; adjacency_list = adjacency_list->next) {
        if (strcmp(adjacency_list->from, city1) == 0) {
            ++number_of_cities_in_graph;
        } else if (strcmp(adjacency_list->from, city2) == 0) {
            ++number_of_cities_in_graph;
        }
    }
    switch (number_of_cities_in_graph) {
    case NO_CITIES: {
        addTwoCitiesToTheGraph(graph, city1, city2, distance);
        break;
    }
    case ONE_CITY: {
        addOneCityToTheGraph(graph, city1, city2, distance);
        break;
    }
    case TWO_CITIES: {
        addNoCityToTheGraph(graph, city1, city2, distance);
        break;
    }
    default:
        break;
    }
    clearBuffer();
}
void addConnection ( Graph_t * graph ) { char city1 [ G_CITYS_NAME_LENGTH ] ; char city2 [ G_CITYS_NAME_LENGTH ] ; double distance = 0 ; programError_t what_error = NO_ERROR ; size_t number_of_cities_in_graph = 0 ; do { printErrorUsersActions ( what_error ) ; getCitysName ( FIRST_CITY , city1 ) ; what_error = checkIfNameIsCorrect ( city1 ) ; } while ( what_error != NO_ERROR ) ; do { printErrorUsersActions ( what_error ) ; getCitysName ( SECOND_CITY , city2 ) ; what_error = checkIfNameIsCorrect ( city2 ) ; if ( what_error == NO_ERROR ) what_error = checkIfNamesAreIdentical ( city1 , city2 ) ; if ( what_error == NO_ERROR ) { what_error = checkIfConnectionIsInGraph ( graph , city1 , city2 ) ; } } while ( what_error != NO_ERROR ) ; do { printErrorUsersActions ( what_error ) ; getDistanceBetweenCities ( & distance ) ; what_error = checkIfDistanceIsCorrect ( distance ) ; } while ( what_error != NO_ERROR ) ; AdjacencyList_t * adjacency_list ; for ( adjacency_list = graph -> head ; adjacency_list != NULL ; adjacency_list = adjacency_list -> next ) { if ( strcmp ( adjacency_list -> from , city1 ) == 0 ) { ++ number_of_cities_in_graph ; } else if ( strcmp ( adjacency_list -> from , city2 ) == 0 ) { ++ number_of_cities_in_graph ; } } switch ( number_of_cities_in_graph ) { case NO_CITIES : { addTwoCitiesToTheGraph ( graph , city1 , city2 , distance ) ; break ; } case ONE_CITY : { addOneCityToTheGraph ( graph , city1 , city2 , distance ) ; break ; } case TWO_CITIES : { addNoCityToTheGraph ( graph , city1 , city2 , distance ) ; break ; } default : break ; } clearBuffer ( ) ; }
FUNCTION NAME: addConnection
 DESCRIPTION:
 Function gets from user names of cities, that create a
 connection that will be added to the graph.
FUNCTION NAME : addConnection DESCRIPTION : Function gets from user names of cities that create a connection that will be added to the graph .
/* First, get cities names and a distance between them. */ /* Check if connection is or is not already in the graph */ /* If everything is fine, then add a connection to the graph .*/ /* Check how many times given cities are in the graph. */