Computing.Net > Forums > Programming > Word wrap in C++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Word wrap in C++

Reply to Message Icon

Name: Pete
Date: August 12, 2002 at 12:44:28 Pacific
Comment:

Is there a way, when programming for the console in C++, to do a word wrap-like function. In which the words are moved to a new line if they cannot fit on the line they are on instead of being cut half way through and finished on another line. If ther is a way to do this, I'd really appreceate the help.

Thanks,
Pete Johnson



Sponsored Link
Ads by Google

Response Number 1
Name: hmm
Date: August 12, 2002 at 15:13:45 Pacific
Reply:

someone helped me with this question
before... here's the function... i call it
neatprint..

void neatprint(FILE *fp, char string[], short maxLineWidth) {

short startIndex;
short endIndex;
short actualLineWidth;

/* Do nothing if invalid inputs are received. */
if (fp == NULL || string == NULL || maxLineWidth = the ending index */
while (startIndex maxLineWidth) {
while (actualLineWidth > 0 &&
!isspace( string[ startIndex+actualLineWidth-1 ]) &&
!isspace( string[ startIndex+actualLineWidth ]) ) {
--actualLineWidth;
}
}


/* Output desired part of line. */
if (startIndex 0) {
fprintf(fp,"%.*s\n",actualLineWidth, &string[ startIndex ]);
}

/* Move pointer to next section of buffer. */
startIndex += actualLineWidth;
}
}

//syntax neatprint(stdout, chararray, 70);


Good Luck

www.akilla.tk


0

Response Number 2
Name: ahh....
Date: August 12, 2002 at 15:15:55 Pacific
Reply:

ah... all the code doesn't appear in this
forum no matter how hard i try... i can't help it, sorry.


0

Response Number 3
Name: Berdon Magnus
Date: August 12, 2002 at 22:16:20 Pacific
Reply:

Then post it at www.subduck.com. Where all text is displayed on the screen!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Dynamic Variable Names Real Player Tray Icon



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Word wrap in C++

scanning a word and strcmp in C www.computing.net/answers/programming/scanning-a-word-and-strcmp-in-c/13333.html

Simple design questions in C++ www.computing.net/answers/programming/simple-design-questions-in-c/4384.html

help me in C++ www.computing.net/answers/programming/help-me-in-c/2812.html