0
C++ forbids comparison between integer and pointer
I was solving a code coach problem in this app called "2D map" which is basically a problem where a 5x5 map is inputted and you have to count how much steps ( if you can only move vertically and horizontally ) are needed to get from the first "P" to the other (Sample input: XXXPX,XXXXX,XXXXX,PXXXX,XXXXX) Everything was going well but when i tried to run the code an error showed up telling me that at Line 18 C++ forbids comparison between integer and pointer... but i'm not comparing an integer at all here... im only comparing "P" with input[i] So what's actually happening? Why? And how can i fix it? My code: https://code.sololearn.com/cS4KQ8c9xTyd/?ref=app
1 Antwort
+ 5
You probably meant 'P'. If you use double quotes, then it is a C-string literal. And that is de facto a pointer into a read-only memory segment. With single quotes it is a char, which is an integral type like int.