这是完成单词搜索的任务的一部分。我必须使用命令行参数来搜索预定的二维数组。我只需要搜索水平(从左到右),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