Click to See Complete Forum and Search --> : string on multiple lines in c
I want to make a long string in C using multiple lines.
I try "This is a long ...................\
............... string"
and the a unprintable character is displayed on the output for \
how do I do this without using strcat?
Strogian
08-10-2005, 12:59 PM
The normal way of doing it is taking advantage of the fact that adjacent strings are concatenated by the preprocessor.
"This is a long ..............."
"................... string"
Strogian
08-10-2005, 01:00 PM
Just curious, what happens if you output something like this:
"This is a long ...............\n .............string"
Because that's what I imagine your string looks like, to the compiler. Do you get the same unprintable character?
okay I got macros and strings confused.
Galen of Edgewood
08-11-2005, 05:34 PM
xrax, did you get it figured out?
Remember, if you don't tell C to go to the next line, it'll continue to print on that same line until it can't anymore. The '\n' forces C to go to the next line.
yes, figured it out. The \ was telling the precompiler to put it on the same line but it was also printing a character in it's place. it should only be used in macros (#define)
Vengance_01
09-06-2005, 12:18 AM
hum I am not sure what you meant, but you just wanted that be outputed to the screen. Code should look like this right?
// Messing Around Chp 2
#include <iostream>
using namespace std;
int main()
{
cout << "This is a long................... \n";
cout << "....................... String" << endl;
return 0;
}
cout is not available in C and the << operator is a bit shift in C. plus that is 2 strings not one longer string. for macros (pre-processor #define) on multiple lines you add the \ to the end of a line to tell the preprocessor to go to next line. the problem was that the preprocessor was combining the 2 lines but including the \ in the string.
The normal way of doing it is taking advantage of the fact that adjacent strings are concatenated by the preprocessor.
"This is a long ..............."
"................... string"