0

I need to check into a loop if the user inserts '\' for exiting from the menu.

while(choise != '\'){
 // do stuff
} 

But I get this error:

error: missing terminating ' character

f.saint
  • 33
  • 2
  • 6

2 Answers2

5

Backslashes are special characters and need to be escaped with another backslash:

while (choice != '\\') {
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
4

\ backslash is an escape character.

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly [here].

So you should do:

while (choise != '\\'){
  // do stuff
}
granmirupa
  • 2,780
  • 16
  • 27