merlin2011
merlin2011

Reputation: 75545

Is there a built-in way to parse standard escape sequences in a user-supplied string in C?

In C, if I put a literal string like "Hello World \n\t\x90\x53" into my code, the compiler will parse the escape sequences into the correct bytes and leave the rest of characters alone.

If the above string is instead supplied by the user, either on the command line or in a file, is there a way to invoke the compiler's functionality to get the same literal bytes into a char[]?

Obviously I could manually implement the functionality by hardcoding the escape sequences, but I would prefer not to do that if I can just invoke some compiler library instead.

Upvotes: 4

Views: 115

Answers (1)

unwind
unwind

Reputation: 399753

No, there's no standard function to do that.

A suggestion for a non-standard library solution is to use glib's g_strcompress() function.

Upvotes: 5

Related Questions