Search code examples
cstringcharcomparestrcmp

How to compare a string with symbol '\'


I have a project and somewhere in my code I'm writing this:

else if (character[0] == '\'){

How can I compare my character with this symbol? Every other symbol that I tried to compare like ,, ;, etc. is done and this is the only symbol that I'm getting a wrong message.


Solution

  • The backslash \ is used as an escape character, so you would need to write:

    else if (character[0] == '\\'){
    

    In this case the backslash is being used to escape itself.