Question:
C Programming question about escape characters?
shadow4light
2011-09-18 23:18:54 UTC
I'm writing a lexical analyzer, and I'm wondering how to check for escape characters.

For example:

if (character == ' \ ') --> I'm aware that this is wrong, but I don't know the correct way of doing this.

I've already tried: ' \\ ' and ' \ ' '
And neither of them work.

Please help me.
Thank you in advance.
Four answers:
JockyMc
2011-09-19 00:28:33 UTC
'\\' is correct. if this isn't working, what error are you getting, because it won't be down to this?
anonymous
2016-12-01 12:36:37 UTC
Linux is transportable, or has been ported to truly some distinctive hardware. there are a number of conditional compilation flags to deal with optimization on distinctive hardware. Having quite transportable binary code that would run on something from an 80386 to a sixty 4-bit Opteron could make it sluggish on greater useful hardware that has greater training that don't exist on the older CPUs. One place that assembly is used is interrupt calls and semaphore managing. in case you like to stipulate precisely what training are used, and choose to renowned which registers would properly be effectively utilized in an interrupt ordinary, you employ assembly. there is yet another remark "the Linux kernel can't link with the widely used C libraries (because of fact that, at their middle the C libraries count on structures calls that are presented via the kernel --- so as that would modern a classic fowl-and-egg problem)"
justme
2011-09-19 06:26:23 UTC
If you are trying to find an escape character in a string, you will not find "\n" for example. When you code "\n" in a string it is converted to the new line character (0x0d or 0x0a, cant remember). So when parsing a string you wont actually find a \ in the string, instead you will find the HEX representation of the escape character.



With that said, you CAN do this:



if (character == '\n') and find the new line character.
anonymous
2011-09-18 23:53:16 UTC
character == '\\' is correct.



EDIT:



Basically, you'll test for a single backslash from a file by comparing the character read with '\\'. '\'' is a single quote.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...