Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,664 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 3,654 people online right now. Registration is fast and FREE... Join Now!




typing long text in printf statement

 
Reply to this topicStart new topic

typing long text in printf statement

rhome
post 1 Oct, 2006 - 10:31 AM
Post #1


New D.I.C Head

*
Joined: 1 Oct, 2006
Posts: 1


My Contributions


I have to type a long text in a printf statement in c.
I would like to "TYPE" the second half of the text in second line.
But the text has to be printed "CONTINUOUSLY".

I cannot press "enter" and type in the next line.

Does anybody have solution to this other than using 2 printf statements in successive manner??? blink.gif
User is offlineProfile CardPM

Go to the top of the page


Jayman
post 1 Oct, 2006 - 12:14 PM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,819



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Yes, there is a way. It requires that you use purely format specifiers to denote the position of the text you want to display. And then comma seperate string literals after the format specifers, similar to how you list variables.

Example:
CODE

printf("%s%s%s%s", "This is a very long line of text that I am going",
       " to use as an example of how you can split several lines of text",
       " in a single printf statement onto several different line that printf",
       " function will allow");
User is offlineProfile CardPM

Go to the top of the page

evoisard
post 29 Oct, 2007 - 02:08 AM
Post #3


New D.I.C Head

*
Joined: 29 Oct, 2007
Posts: 2


My Contributions


Or you can use backslashes that will make the lines joined together at compilation time (note that it works for any line of code, not only strings):

CODE

printf( "This is a very long line of text that I am going \
to use as an example of how you can split several \
lines of text, in a single printf statement onto several \
different line that printf function will allow");

[/quote]

Eric
User is offlineProfile CardPM

Go to the top of the page

evoisard
post 29 Oct, 2007 - 02:22 AM
Post #4


New D.I.C Head

*
Joined: 29 Oct, 2007
Posts: 2


My Contributions


or, if you prefer it cleaner, simply:

CODE

printf( "This is a very long line of text that I am going "
          "to use as an example of how you can split several "
          "lines of text, in a single printf statement onto several "
          "different line that printf function will allow");



Eric

This post has been edited by evoisard: 29 Oct, 2007 - 02:30 AM
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 06:51AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month