Hi guys,
I am writing a code to construct the shortest path between 2 points using the floyd warshall algorithm. However I am running into trouble while trying to print the results of my getpath routine. Basically what I do is I call the routine from main() using this code:
Code:
FILE *ofp=fopen("path.txt","w");
fprintf(ofp," ");
for (i = 0; i < n; ++i)
{
for (j = i; j < n; j++)
{
printf("The shortest distance between %d and %d is obtained by going through ", i, j);
fprintf(ofp,"%d ",i);
getpath(i,j);
fprintf(ofp, "%d \n ",j);
printf("\n");
}
}
fclose(ofp);
Code:
int getpath(int i, int j)
{
if (dist[i][j] == 0 )
{
}
int intermediate = next[i][j];
if (intermediate == 0)
{
}
else
{
getpath(i, intermediate);
printf("%d ", intermediate);
getpath(intermediate, j);
}
return 0;
}
The problem is this. The get path utility is printing the intermediate nodes but I want those intermediate nodes but I want it to print those intermediate nodes in the path file. I have outputting the data from the getpath() routine, returning the values of k, and other stuff but nothing seems to be working. Please HELP!!!