“格式的参数太多了”警告

时间:2015-04-27 20:36:50

标签: c matrix adjacency-matrix

#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;
}

程序需要检查给定的表示树的11X11矩阵中的2个给定索引(u,v)之间是否存在路径。 当我尝试在终端编译时,我得到了这个massege:

  

adjacency.c:41:1:警告:格式的参数太多[-Wformat-extra-args]   除此之外,该计划不起作用。如果我输入(1,8)它应该返回true但它返回false。

1 个答案:

答案 0 :(得分:4)

您的格式说明符"The answer is %d""\n"适用于一个参数,但您传递了两个path(arr, u, v)".\n"

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

大概你需要

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