[英]ISO C++ forbids comparison between pointer and integer [-fpermissive] error in devc++
ISO C++ forbids comparison between pointer and integer [-fpermissive] error in devc++ its basically a game of dot and box the error is in check function at around six places where i have compared like a[i-1][j]=="_" help me figure out the problem ISO C ++禁止在devc ++中指针和整数[-fpermissive]错误之间的比较它基本上是一个点和框的游戏,错误是在检查函数中的六个地方,我比较像[i-1] [j] ==“ _“帮我解决问题
#include <stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int p=0;
int g=1;int p1s=0;int p2s=0;
char pl,pt1,pt2;
char p1[20];
char p2[20];
char a[17][35];
void printer(){int i,j;
system("cls");
printf("score ----> %s => %d %s => %d\n",p1,p1s,p2,p2s);
printf(" 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 \n");
for(i=0;i<17;i++){if(i%2==0)printf("%c ",'a'+(i/2));for(j=0;j<35;j++)printf("%c ",a[i][j]);printf("\n");}
}
void check(char c,char d,int i1,int i2,int p){int i,j,k,l;
if(c==d){
i=c-'a';i=2*i;j=2*i1+1;
if(a[i-2][j]=="_" && a[i-1][j-1]=="|" && a[i-1][j+1]== "|"){if(p%2==0){p1s++;a[i-1][j]=pt1;};if(p%2==1){p2s++;a[i-1][j]=pt2;}}
if(a[i+2][j]=="_"&&a[i+1][j-1]=="|"&&a[i+1][j+1]=="|"){if(p%2==0){p1s++;a[i+1][j]=pt1;};if(p%2==1){p2s++;a[i+1][j]=pt2;}}
}
}
void game(){ int i,j,k,i1,i2,i3;
for(i=0;i<17;i++){for(j=0;j<35;j++){if(i%2==0){if(j%2==0)a[i][j]='.';else a[i][j]=' ';}else a[i][j]=' ';}}
printer();
char c[4];char d[4];
while(g==1){ if(p%2==0){printf("%s's turn",p1)}
if(p%2==1){printf("%s's turn",p2)}
printf("enter first coordinate\n");
gets(c);
printf("enter second coordinate\n");
gets(d);
i1=10*(c[1]-'0')+(c[2]-'0');
i2=10*(d[1]-'0')+(d[2]-'0');
if(c[2]=='\0')i1=c[1]-'0'; /* correction if single digit is entered */
if(d[2]=='\0')i2=d[1]-'0';
i3=d[0]-c[0]+i2-i1;
i3=d[0]-c[0]+i2-i1;
if(i3!=1){printf("invalid move\n");continue;}
if(!((c[0]-'a')<25)&&!((d[0]-'a')<25)){printf("invalid move\n");continue;}
if(!(i1<18)&&!(i2<18)){printf("invalid move\n");continue;}
if(c[0]==d[0]){j=c[0]-'a';j=2*j;k=i2*2+1;if(a[j][k]=='_'){printf("repeated line\n");continue;}else a[j][k]='_';}
if(i2==i1){j=c[0]-'a';j=2*j+1;k=i1*2+1;if( a[j][k]=='|'){printf("repeated line\n");continue;}else a[j][k]='|';}
check(c[0],d[0],i1,i2,p);
printer();
}
}
int main (){
printf("Enter first player's name:\n");
gets(p1);
printf("Enter second player's name:\n");
gets(p2);
pt1=p1[0];
pt2=p2[0];
if(p1[0]==p2[0])pt2=p2[1];
game();
return 0;
getch();
}
i used devcpp for programming a is my 2-d string why is this comparison not valid? 我使用devcpp编程a是我的2-d字符串为什么这个比较无效?
You've mistakenly used the double quotes ""
to denote a char
. 您错误地使用双引号""
来表示char
。 You need to use the single quotes ''
to denote a char
. 您需要使用单引号''
来表示char
。
A double quote " "
denotes a string which essentially gives you the base address, which is nothing but a pointer type. 双引号" "
表示一个字符串 ,它基本上为您提供了基址,这只是一个指针类型。 You cannot compare a pointer with a value, like a[i-2][j]
, which is a char
type here. 您无法将指针与值进行比较,例如a[i-2][j]
,这里是char
类型。
Use it like 像它一样使用它
a[i-2][j]=='_'
and so on and you should be good to go. 等等,你应该好好去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.