我有以下代碼:錯誤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