How can I make a string full of text print without having to break a word and go to the other line??
How can I make a string full of text print without having to break a word and go to the other line??
using printf.....I wanted top be printed in the screen
ex: char line[]="hkjhk kjhkjhkjkjjkjkjj kjkjkjk jkjkljljkl ljljljl jljljlj jljljlj ljljl jljljljl jljljl jljll;;lk;lk; l;; k;k;k;k k;k;k; ;k;k;k;k";
printf("%s",line);
if you're looking for wordwrap in console,
look here.....
GOOD LUCKCode:void mywordwrap(FILE *fp, char string[], short maxLineWidth) { short startIndex; short endIndex; short actualLineWidth; if (fp == NULL || string == NULL || maxLineWidth <= 0) { return; } startIndex = 0; endIndex = strlen(string); while (startIndex < endIndex) { while (startIndex < endIndex && isspace( string[startIndex] )) { ++startIndex; } actualLineWidth = maxLineWidth; if (endIndex - startIndex > maxLineWidth) { while (actualLineWidth > 0 && !isspace( string[ startIndex+actualLineWidth-1 ]) && !isspace( string[ startIndex+actualLineWidth ]) ) { --actualLineWidth; } } if (startIndex < endIndex && actualLineWidth > 0) { fprintf(fp,"%.*s\n",actualLineWidth, &string[ startIndex ]); } startIndex += actualLineWidth; } } //syntax mywordwrap(stdout, chararray, 70);
Last edited by moonwalker; 08-23-2002 at 11:25 AM.
WOW can it be a bit simpler!!!
>WOW can it be a bit simpler!!!
yeah, do printf a dozen times and then
see where it's cutting off... go there and put a \n
in the string.
>How can I make a string full of text print without having to break a word and go to the other line??
The problem with this is that you do not know the width of the console window, so it is difficult to know when to wrap the word to the next line. The simplest method is to print words until the next word will hit the edge of the console screen, insert a newline before the word and keep going. Once again this involves knowing how many characters one line of the console can hold before wrapping.
-Prelude
My best code is written with the delete key.