Hi,
I have been trying to get my head around arrays, though i understood it but have tripped over again with multidimensional arrays.
Code:int main(int argc, char *argv[]) { int num_roads = argc - 1; /* to change by 1 later !!!!!! */ /* To create an integer array from the input char array */ int i; int road_type[num_roads]; for(i = 0; i < num_roads; i++) { road_type[i] = atoi(argv[i+1]); } /* -----------------end road type thing-------------------*/ int num_routes = get_num_routes(num_roads, road_type); printf("Number of possible routes is %d\n", num_routes); /* Create an integer array showing possible routes i.e. road 1 to road 4 would be 14 */ int j; int route_list[num_routes][2]; for(j = 0; j < num_routes; j++) { route_list[j][0] = get_route_list(num_roads, num_routes, road_type, j, 0); printf("%d", route_list[j][0]); route_list[j][1] = get_route_list(num_roads, num_routes, road_type, j, 1); printf("%d\n", route_list[j][1]); } /* -----------------end route list thing-------------------*/ route_check(num_roads, num_routes, road_type, route_list); return 0; } /* Create an array showing 1 for routes that can not occur simultaneously */ int route_check(int num_roads, int num_routes, int *road_type, int route_list[][1]) { int i, j, k; int from = 9; int to = 9; int route_holder[] = {0,0}; int route_clear1; int route_clear2; int side1[num_roads]; int side2[num_roads]; int invalid_routes[num_routes][num_routes]; /* write function to clear this. Stores 1 for invalid route */ for(i = 0; i < num_routes; i++) { from = route_list[i][0]; to = route_list[i][1]; for(j = 0; j < num_routes; j++) { for (k = 0; k < num_routes; k++) { get_side1(side1, num_roads, road_type, from, to); get_side2(side2, num_roads, road_type, from, to); if(route_list[j][0] == side1[k]) { route_holder[0] = j; route_clear1++; } if(route_list[j][1] == side1[k]) { route_holder[1] = j; route_clear1++; } if(route_list[j][1] == side2[k]) { route_holder[1] = j; route_clear2++; } if(route_list[j][1] == side2[k]) { route_holder[1] = j; route_clear2++; } } } } return 0;//*invalid_routes; } /* Function to get a list of of the roads on either side of a particular route. */ void get_side1(int *side1, int num_roads, int *road_type, int from, int to) { int i = from; int place_holder = 0; while(i != to) { if(i != num_roads - 1) { side1[place_holder] = i; place_holder++; } else if(i == num_roads - 1) { side1[place_holder] = i; place_holder++; i = 0; } i++; } if (road_type[from] == 2) { side1[place_holder] = from; place_holder++; } side1[place_holder] = 9; } /* Function to get a list of of the roads on either side of a particular route. */ void get_side2(int *side2, int num_roads, int *road_type, int from, int to) { int i = from; int place_holder = 0; while(i != to) { if(i != num_roads - 1) { side2[place_holder] = i; place_holder++; } else if(i == 0) { side2[place_holder] = i; place_holder++; i = num_roads - 1; } i--; } if (road_type[to] == 2) { side2[place_holder] = to; place_holder++; } side2[place_holder] = 9; }
I have cut out most of the code from the program, sorry there is still so much to read i am not sure what parts are involved in the error.
The error is...
in main: passing arg 4 of 'route_check' from incompatible pointer type.
and before i managed to create that error i got....
error subscripted value is neither array nor pointer
for the parts in the route_check fuction where i used route_list[j][1] or route_list[j][0]
I haven't finished writing route_check yet, that why it don't make much/any sence. Was just trying to iron out any errors at this stage.
Any help on these errors would be great.
Thanks again,
-Nick



LinkBack URL
About LinkBacks


