-3
#include <stdio.h>

#define N 11
enum {FALSE, TRUE};
typedef int adj_mat[N][N];

int path2(adj_mat A, int u, int v, int temp)
{
if(u == temp && A[u][v] == TRUE)
return TRUE;

if(A[u][v] == FALSE)
return path2(A, u-1, v, temp);

if(A[u][v] == TRUE)
return path2(A, N, u, temp);

return FALSE;
}

int path(adj_mat A, int u, int v)
{
return path2(A, N, v, u);
}



int main()
{

int arr[N][N]= {{0,1,1,1,0,0,0,0,0,0,0},{0,0,0,0,1,1,1,1,1,0,0},
{0,0,0,0,0,0,0,0,0,1,0},{0,0,0,0,0,0,0,0,0,0,1},{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}};
int u;
int v;
printf("please enter two numbers \n");
scanf("%d %d", &u, &v);
printf("The answer is %d" "\n", path(arr, u, v),".\n");
return 0;
}

the program needs to check if there is a path between 2 given indexes (u,v) in a given 11X11 matrix that represents a tree. when i try to compile at the terminal i get this massege:

adjacency.c:41:1: warning: too many arguments for format [-Wformat-extra-args] besides that, the program doesnt work. if i enter (1,8) it supposed to return true but it returns false.

user4831626
  • 9
  • 1
  • 1
  • 6
  • Your last `printf` has only one format specifier (`%d`) but you've given it 2 arguments, `path(...)` and `".\n"`. – lurker Apr 27 '15 at 20:39
  • tnx. but when i put (1,8) it returns 0 but it should return 1 – user4831626 Apr 27 '15 at 20:49
  • What do you mean *it returns 0*? What returns 0? – lurker Apr 27 '15 at 21:13
  • sorry, i didnt attached pics but if you look at the matrix, if i use path(1,8) it supposed to return TRUE because 1 has a path to 8. but it returns FALSE – user4831626 Apr 27 '15 at 21:18
  • Your arguments to `path` and `path2` seem mixed up. From `path(A, u, v)` you call `path2(A, N, v, u)` but the declaration for `path2` is `path2(A, u, v, temp)`. Is that what you intended? – lurker Apr 27 '15 at 21:57
  • Yes, beacause i wanted to check all of the first cullom idexes to find wich one is the "father" of v and then i switch them. u becoms v and v becoms u. temp always stays with u first value and when it gets there and u is equal to v and also a[u][v] is TRUE it returns TRUE. hope you understand – user4831626 Apr 27 '15 at 22:10
  • That's a different question and you might want to open a new one, giving some details on what you tried already to debug/verify the behavior of your function. The question of why you get the format string error has already been answered and accepted. – lurker Apr 28 '15 at 14:06

1 Answers1

4

Your format specifier "The answer is %d""\n" is for one argument, but you pass two, path(arr, u, v) and ".\n":

printf("The answer is %d" "\n", path(arr, u, v),".\n");

Presumably you need

printf("The answer is %d.\n", path(arr, u, v));
juanchopanza
  • 223,364
  • 34
  • 402
  • 480