I’m currently writing a parser for my toy language, and as a part of that parser i have written print function that well… basically prints its argument. For string constant all it does is
printf("%s", pointer);
so
print("\n")
should be executed as
printf("%s", ptr_to_loaded_string);
(more or less)
However, my current problem is, that C escapes special character sequences while reading script file. So instead of “\n” I get “\\n”.
My question is: is there some way I can avoid the escaping of this sequences, and if not what’s the best way to deal with them? I’m currently thinking about search and replace – replace each sequence of 2 ‘\’ with one ‘\’, but it may be a little problematic (string length change, reallocing, etc.) – i want to avoid that solution unless it’s absolutely necessary.
edit: argh, stackoverflow escaped my example….
It’s not that C is un-escaping your sequences — it’s that it’s simply leaving them alone, so your “\n” in the input stream is read as two characters (‘\’ and ‘n’).
Here’s some code I wrote years ago to deal with this: