Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line continuation

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
Hi,

puts("enter last name, first name, id# separated");//line1
puts("by spaces, then press enter."); //line2

Can I combine these 2 puts() into 1. For example

puts("enter last name, first name, id# separated //line1
by spaces, then press enter."); // line2

I know my example doesn't work, but just to give you an idea of what I want.

Thanks in advance.
 
Yes, and that should compile (w/o the comment in the middle)
Code:
puts("enter last name, first name, id# separated  
    by spaces, then press enter.");

But you probably want to use escape chars:
Code:
\n  newline  to get a new line
\t  tab      to get a tab
\0  null     to get a null char
\\  \        to get a \, sine \ is the escape char

So you'd want to do:
Code:
puts("enter last name, first name, id# separated[green]\n[/green]by spaces, then press enter.");

Note that it is right against the other text, this is so that you don't get a space at the begining of the second line You can seperate it from the word seperated, but not from the word by w/o changing the format.
 
some how I need the this '\' at the end of the line. It works like this.

puts("enter last name, first name, id#\
separated\nby spaces, then press enter.");

Thanks jstreich
 
Code:
   puts("enter last name, first name, id# separated "  // line1
        "by spaces, then press enter.");               // line2
 
Enter chars shouldn't be in string literals, even if allowed... You should use \n ... Using returns in a string literal should create a compiler warning if the compiler is worth it's salt.
 
Hi jstreich,

Enter char? Do you mean \? In my original code
puts("enter last name, first name, id# separated
by spaces, then press enter.");
,
the compiler was asking for the '\' (which I didn't notice in the first place).

Another question, can I declare and initialize pointer in the same statement? Instead of coding them separatly like the below.
int *ptr;
ptr = &var;

Thanks again
 
I said \n
for newline. the \ is an escape
\' and \" are how to get a the chars ' and " (respectivly). Without them the compiler will thing you are want to end or begin a literal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top