Multiline strings

  • Thread starter Martin Johansen
  • Start date
M

Martin Johansen

Hi guys

What is the best way to achieve multiline strings such as:

puts("
<html>
</html>
");

without using \ at the end or "" on each line?

thanks!
 
M

Me

What is the best way to achieve multiline strings such as:
puts("
<html>
</html>
");

without using \ at the end or "" on each line?

Write your own preprocessor to convert newlines to \ inside strings or
find a compiler that allows multi-line strings in its grammar as an
extension. Otherwise it can't be done in standard C:

string-literal:
" s-char-sequence-opt "
L" s-char-sequence-opt "
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
double-quote ", backslash \, or
new-line character
^^^^^^^^^^^^^^^^^^
escape-sequence
 
M

Martin Ambuhl

Martin said:
Hi guys

What is the best way to achieve multiline strings such as:

puts("
<html>
</html>
");

without using \ at the end or "" on each line?


puts("\n"
"<html>\n"
"</html>\n");
 
C

CBFalconer

Martin said:
What is the best way to achieve multiline strings such as:

puts("
<html>
</html>
");

without using \ at the end or "" on each line?

puts("<html>" "blah blah" "</html>\n");

is identical if effect to:

puts("<html>blah blah</html>\n");

i.e. adjacent strings (no commas etc) are simply concatentated.
You can spread them over multipl lines too:

puts("<html>"
"blah blah"
"</html>\n");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top