Thanks for your reply.
Ok, that was a poorly thought out example. Maybe that isn't the problem.
I tried to make an example because it'd take ages to explain what the entire purpose of this code is. I have cut out the relevant parts of the code and placed them below. The array road_type holds 0's 1's and 2's in a random order, it's total size is num_roads.
At that point where the #_#_ bit is the route list array is working fine for the first loop of that j for loop. Then when it loops through again i get problems, the program seems to assign the value of i to the route_list[place_holder] = j; I cant work out why this is.
#define INTO 0
#define OUTOF 1
#define TWOWAY 2
/* Prototypes of local functions */
int get_route_list(int num_roads, int num_routes, int *road_type, int y, int x);
int main(int argc, char *argv)
/* Create an integer array showing possible routes i.e. road 1 to road 4 would be 14 */
for(j = 0; j < num_routes; j++)
route_list[j] = get_route_list(num_roads, num_routes, road_type, j, 0);
route_list[j] = get_route_list(num_roads, num_routes, road_type, j, 1);
/* -----------------end route list thing-------------------*/
/* Create an array that lists the possible routes */
int get_route_list(int num_roads, int num_routes, int *road_type, int y, int x)
int i, j;
int place_holder = 0;
for(i = 0; i <= num_roads; i++)
if(road_type[i] == TWOWAY || road_type[i] == INTO)
for(j = 0; j <= num_roads; j++)
if(road_type[j] == TWOWAY || road_type[j] == OUTOF)
if(i == j)
route_list[place_holder] = i;
route_list[place_holder] = j;
/* #_#_#_#_#_#_#_#_# */
I'm struggling to explain this without posting the whole code and assignment details. If there is an obvious problem then it'd be great to hear what it is. Otherwise i'll just bang my head against the wall for another couple of hours and hope an answer falls out