2

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.

user5799707
  • 43
  • 1
  • 1
  • 4
  • 4
    Parentheses are not special characters in C string or character literals, they don't need to be escaped. – Some programmer dude Mar 06 '16 at 07:04
  • 1
    Drop the escape sequence. Use just `")"`. See http://stackoverflow.com/a/34958449/434551 for valid escape sequences. – R Sahu Mar 06 '16 at 07:05
  • I was treating it as a regular character and it was still throwing off all of my parenthesis, that's why I tried escaping it. – user5799707 Mar 06 '16 at 07:07
  • I'm not getting any warnings/errors on my computer... (http://rextester.com/MTOR1328) – Idos Mar 06 '16 at 07:17
  • Nevermind, I'm stupid and was recursively calling a function by the wrong name, which gave me errors related to parenthesis so I assumed it had to be the print statement. – user5799707 Mar 06 '16 at 07:23
  • Happens to the best of us... Anyways cheers for figuring it out – Idos Mar 06 '16 at 07:24

4 Answers4

4

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(")");
Idos
  • 15,053
  • 14
  • 60
  • 75
2

try this:

#include <stdio.h>

int main()
{
  printf("Printing quotation mark \")\" ");
}

you need to add an escape character to get the quote to print which in this case is \"

This will result in Printing quotation mark ")"

mikefaheysd
  • 126
  • 4
0

just write parenthesis in double quote " " ,because parenthesis is not a escape character .

try this :

 #include<stdio.h>
 int main(){
 printf( "(  )" ); // print  parenthesis here
 }
Fingalzzz
  • 109
  • 14
rohit prakash
  • 565
  • 6
  • 12
0

Hope this helps.

Using variables seems to be a viable solution using my compiler.

#include <stdio.h>

int main() {
    char var = ')';
    printf("Hello, World!\n");
    printf("Success :%c",var); //As you can see this is one way to go about the problem
    return 0;
}


Ashwin
  • 1