0

I have a char pointer that points to a string: "123 \\n." if I do a printf ("%s", char_pointer) I see 123 \n. instead of 123 . What would be the easiest way to get rid of the extra \ so that it displays properly assuming I have can't change the formatting of the original string?

This is an example of the string I am handling

const char *source = \
" printf (\"This is a test %d %d \\n.\",4,3);                                       \n";
1
  • Show us where you assign the value "123\n" to char_pointer. Sep 3, 2012 at 20:04

1 Answer 1

0

you have two slashes there. That means that in \\n the first \ escapes the second \, and it is printed as-is. The following n is interpreted as a standalone character instead of part of \n.

If you want the \ to be printed at the end of the line, you need an additional \ there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.