for(j=0;j<nodes;j++){ //changes source node number charcter if(j==0){char nod[1] = "a";} else if(j==1){char nod[1] = "b";} else if(j==2){char nod[1] = "c";} else if(j==3){char nod[1] = "d";} else if(j==4){char nod[1] = "e";}; int d = rt[i].from[j]+1; if(d==1){char nod[1] = "a";} else if(d==2){char next[1] = "b";} else if(d==3){char next[1] = "c";} else if(d==4){char next[1] = "d";} else if(d==5){char next[1] = "e";}; printf("\t\n %s %d %s ",nod,rt[i].dist[j],next); }
this prints out same both strings, , prints out next , not print out nod @ all. ie.
for router a 0 b 2 b c 3 c c 5 c b 5 b
when should like:
for router a 2 b 0 b c 4 c d 4 c e 3 b
any appreciated, thanks.
you redeclaring nod
, next
in each if block, , when block ends, go out of scope.
so not printing modified nod
or next
, 1 declared before for
loop starts.
you don't need nod
or next
print values, print them directly or,
for(j=0;j<nodes;j++) { int d = rt[i].from[j] + 1; printf("\t%c %d %c\n", 'a' + d - 1, rt[i].dist[j], 'a' + d - 1); }
would give ouput want.