• C

C language - how to ignore special characters.


I have a value is dynamic which returned from server, value looks like: "\x001\x003\x008\x008"

I want to captured that value then send back to the server but I don't know how to process.

Because the value is dynamic so I cannot set fixed like: "\\x001\\x003\\x008\\x008"

Does anyone have idea how to replace or escape the special character "\" in C language?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The way to represent the '\' character in C is '\\' (i.e. two slashes in source code = a single slash at run-time).
I wonder if this might not help (since I'm not sure how much you do and don't know about the esc character).

The Escape character only hold meaning in source code.  The compiler will read the escape and interpret it properly.

Part of what you are showing is the combined escape sequence of \x which means you are attempting to represent a character with a hex number.  If you replace the x with a 0 then you are attempting to represent a character with octal numbers.

So the following are three ways to represent a '\' in source code:
'\\' == '0134' == '\x5C'      //This is a logical TRUE statement.

Here is another example that is more mundane:
'A' == '\0101' == '\x41'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
value looks like: "\x001\x003\x008\x008"

do you see the above in the debugger? or in a log file? Is it a string (text) enclosed by double quote characters "" ? as HooKooDooKu explained the string looks like a textual output of a binary byte array

unsigned char bytes[4] = { 0x1, 0x3, 0x8, 0x8 };

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.