LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to define a constant with CrLf in it?

Hi,

I'm trying to define a constant for a prompt. This prompt includes a CrLf (CR + LF) inside it. (e.g. "ABC CrLf DEF").

Is it possible to write this constant or, do I have to build it into a variable.

CAn you please show me both ways


Thanks
Rafi
0 Kudos
Message 1 of 3
(3,801 Views)
Carriage return and Line feed are both single characters that can be represented as '\r' and '\n' respectively.
This works in a string constant ("Something\r\nNext line") or as a single character (assert(*strchr("abc\r\ndef", '\r') == '\r')).

On an entirely different note, I have found that it can make string constants with like breaks in them easier to read if you do something like this:

const char *message =
"First line ...\r\n"
"Second line ...\r\n"
"Third line.";

The compiler will concatenate these strings at compile time and this way is typically much more readable.

For your reference, the common available special characters are:

null byte: \0
bell character: \a
backspace: \b
horizontal tab: \t
formfeed: \f
newline: \n
carriage return: \r

Also note that since \ is used to denote these characters, to get an actual backslash in a string or as a single character, you have do use 2 (as in "\\" or '\\').

Hope this helps,

Alex
0 Kudos
Message 2 of 3
(3,793 Views)
Thanks Alex,

Thank you very much for your prompt answere.

Will that wrok in your opnion (I don't have the hardware to test my program at this time)?

strstr(buf, "Something\r\nNext Line");

Thanks

Rafi
0 Kudos
Message 3 of 3
(3,787 Views)