我有以下代码:错误scanf函数
#include <stdio.h>
int main() {
int tc,T;
scanf("%d", &T);
for(tc=0; tc<T; tc++){
int flag=0;
int R,C;
scanf("%d %d", &R, &C);
{
int i,j;
int r,c;
int Grid[R][C];
//Read the Grid
for(i=0; i<R; i++){
for(j=0; j<C; j++){
scanf("%d", &Grid[i,j]);
}
}
scanf("%d %d", &r, &c);
{
int Pattern[r][c];
//Read the Grid
for(i=0; i<r; i++){
for(j=0; j<c; j++){
scanf("%d", &Pattern[i,j]);
}
}
//Here we have both the Grid and the Pattern
for(i=0; i<R; i++){
for(j=0; j<C; j++){
if(Grid[i,j]==Pattern[0,0] && ((i+r)<=R) && ((j+c)<=C)){
int x,y;
int innerFlag=1;
for(x=0; x<r; x++){
for(y=0; y<c; y++){
if(Grid[x+i,y+j]!=Pattern[x,y]) innerFlag=0;
}
}
if(innerFlag == 1){
//Set the flag to 1 and break out of the nested loops
flag=1;
j=C;
i=R;
}
}
}
}
//Here all the calculation is done and the flag is set
if(flag==1) printf("YES\n");
else printf("NO\n");
}
}
}
return 0;
}
使我有以下错误:
- 警告:格式 '%d' 需要类型的参数 '诠释' ,但参数2的类型为int()[(sizetype)(C)]' scanf(“%d”,& Grid [i,j]);
- 警告:格式 '%d' 期望类型的参数 '诠释',但参数2具有输入 'INT()[(的SizeType)(C)]' 的scanf( “%d”, & Pattern [i,j]);
你知道这段代码有什么问题吗?
P.S我也检查了网格和模式,它读取垃圾!
规范表格/模式?是否为两个类都重载'[]'作为参数? – mwm314
@ mwm314问题标记为C,代码看起来是C,所以没有超载。 – user3386109
'Grid [i,j]'中的逗号被解释为[逗号运算符](https://en.wikipedia.org/wiki/Comma_operator),所以'Grid [i,j]'与'格[j]的'。 – user3386109