Search code examples
cmatrixadjacency-matrix

"too many arguments for format" warning


#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.


Solution

  • 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));