How to print a parenthesis in C with printf?

user5799707 picture user5799707 · Mar 6, 2016 · Viewed 20.2k times · Source

I am trying to print a parenthesis using: printf("\)"); However, it is giving me the following warning: warning: unknown escape sequence '\)'

I can't seem to find a clear explanation anywhere on how to fix this. I realize it's just a warning, but since it's still treating that as a parenthesis it's throwing off all my other parentheses and giving me errors so that the code does not compile.

EDIT: Treating it as a regular character and just saying printf(")") is not working. It's still mismatching all the parentheses and I have gone through multiple times to make sure I'm not actually missing any.

Answer

Idos picture Idos · Mar 6, 2016

The warning is coming from the C compiler. It is telling you that \ is not a known escape sequence in C. You need to double-escape the slash, like so: \\

Edit: if you just want to print the parenthesis, i.e. the ) then drop the slash altogether and use:

printf(")");