#include <iostream> #include <cstring> using namespace std; int main(){ char s[100] = "(())())"; int p = 0; for(int i(0);i < strlen(s);i++){ if (s[i] == "("){parni++;} } return 0; } 

Why does not work, please tell me.

test.cpp | 9 | error: ISO C ++ forbids comparison between integer and [-fpermissive] |

Closed due to the fact that off-topic by user194374, cheops , aleksandr barakin , pavel , αλεχολυτ 12 Aug '16 at 8:40 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - community spirit, cheops, aleksandr barakin, pavel, αλεχολυτ
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What does "not working" mean? What effect do you expect? Your program displays nothing. - VladD
  • @VladD, the point is not the point, the point is that it gives an error. - goodalien
  • 2
    Yes, you are comparing a character with a string, this is not correct. Most likely you meant s[i] == '(' . - VladD
  • Well, the error is better to write in the question, so that we do not guess. - VladD
  • @VladD, thank you so much! :) - goodalien

1 answer 1

What a wild mix of C and C ++ ... To begin with, it does not "work", but does not compile :

  1. The variable parni not declared anywhere.
  2. Comparing s[i] == "(" incorrect (most likely, it meant a comparison with the symbol '(' ).

However, the compiler speaks about all this explicitly. If your did not say this - throw it in the trash and find a normal one.

 1.cpp: In function 'int main()': 1.cpp:9:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if (s[i] == "("){parni++;} ^ 1.cpp:9:26: error: 'parni' was not declared in this scope if (s[i] == "("){parni++;} ^ 
  • Yes "parni 'is a technical error when entering into the Question :) But for the character, thank you! - goodalien
  • 2
    @ goodalien1125, just do not need to be afraid of errors. They were, are and will be with any programmer, always. But you need to read carefully what they write there. Even if on foreign, the language is quite simple, you can understand. In extreme cases, copy and drive into Yandex. Since this is a mistake that the compiler produces - I assure you, any of them have already been encountered by millions of programmers, discussed a million times, chewed, and even in Russian :) - gottar