Xcode warning, Unknown escape sequence '\ '

With spaces allowed in Mac folder names, it's necessary to use an escape sequence while programming (at least what I'm doing in C right now) and Xcode is complaining about the standard usage of the backslash character, as in:

input = fopen("/Users/joe\ schmoe/namedata.txt", "r");

if one of the folders were named "joe schmoe" with the space in there. Everything works, but the yellow warning tag and highlighting is bothersome.

How do I turn off that incorrect warning?

Answered by giohn in 723322022

Just do input = fopen("/Users/joe schmoe/namedata.txt", "r"); It will work! I have tested it with the default compiler (Apple Clang) and gnu11 language dialect.

Accepted Answer

Just do input = fopen("/Users/joe schmoe/namedata.txt", "r"); It will work! I have tested it with the default compiler (Apple Clang) and gnu11 language dialect.

It's not an incorrect warning.

In C/C++/objC quoted strings, the characters that you need to escape are ", newline, tab, , and a few other control characters. This is true whether the string is a filename or anything else.

This is similar to what you need to do in quoted strings in the shell. But it differs from what you need with unquoted strings in the shell.

Examples:

fopen("Hello World");    // C
cat "Hello World"     # shell
cat Hello\ World    # shell

Now say you have a file with a literal \ in the name (which would be unwise, if you might one day port to Windows, I think, but anyway):

fopen("back\\slash")
cat "back\\slash"
cat back\\slash

I see my question was answered through the escape sequence not being needed in this case. So that's great. I still don't know how to turn off some warning I don't want to be bothered with, but that's another matter and not a real problem, at least for now.

Nice to have this resource here for help and education:-)

how to turn off some warning I don't want to be bothered with

From the command-line, -Wno-THING, where THING is the warning to turn off. For example, I have -Wno-unused-parameter in some of my Makefiles.

In XCode - yeah, it's somewhere in the build settings. You can do it for specific files if you want, I forget how exactly.

It might be unwise to turn this off, though. If you write "\ ", did you mean " " or "\\ " ? There are also complex issues with octal and unicode escape sequences where you may not get what you wanted.

P.S. I now see that this forum mangles backslash characters, so some of what I've written makes less sense than it should. I hope you can decipher it.

Thanks for the extra tips and education. Always nice to know more. Plus, my original "issue" was so easy to fix:-)

Xcode warning, Unknown escape sequence '\ '
 
 
Q