I want to make a long string in C using multiple lines.
I tryand the a unprintable character is displayed on the output for \Code:"This is a long ...................\
............... string"
how do I do this without using strcat?
Printable View
I want to make a long string in C using multiple lines.
I tryand the a unprintable character is displayed on the output for \Code:"This is a long ...................\
............... string"
how do I do this without using strcat?
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"
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.
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)
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.
Quote:
Originally Posted by "Strogian"