這是完成單詞搜索的任務的一部分。我必須使用命令行參數來搜索預定的二維數組。我只需要搜索水平(從左到右),Diagnal(從左上到右下)和Vertical(從上到下)。 一旦我更好地理解指針問題,我將編寫Diag和Vert。字符數組和二維數組指針問題
我得到
warning: comparison between pointer and integer
這發生在以下if語句
if (argv[count] == g[i][j]){
爲什麼我得到了警告,那我在我的指針的理解是防止我做這個失蹤。
我試過的* G和(INT星)G不同變化的不僅僅是警告更壞的結果。
我需要警告的代碼輪到項。
謝謝你幫助新人們。
#include <stdio.h>
#define ROW 3
#define COL 4
#define TRUE 1
#define FALSE 0
int checkHoriz(char *data, char *data2);
main(int argc, char *argv[]){
int count, i, j, rowValue, colValue;
char g[ROW][COL] = {{'a','b','c','d'},
{'d','c','b','a'},
{'x','y','z','d'}};
count=1;
if(argc>1){
for(i=0; i<ROW; i++){
for(j=0; j<COL; j++){
if (argv[count] == g[i][j]){
rowValue = i;
colValue = j;
if(checkHoriz(argv[count],g[i][j]) ==TRUE){
printf("%s appears horizontally starting @ g[%d]{%d]. \n", argv[count], i,j);
}
}
}
}
}else{
printf("No arguments were entered.\n");
}
}
int checkHoriz(char *data, char *data2){
int i = 0;
while (data == data2 && data!=' ' && data2 != '\0'){
data++;
data2++;
}
if(data2 == '\0'){
return 1;
}else{
return 0;
}
}
您可以通過編輯您的問題[此鏈接](http://stackoverflow.com/posts/9552176/edit)。 – ruakh 2012-03-04 04:01:43