简体   繁体   中英

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

#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?

You've mistakenly used the double quotes "" to denote a char . You need to use the single quotes '' to denote a 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.

Use it like

 a[i-2][j]=='_'

and so on and you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM