markiemrboo Posted May 25, 2005 Posted May 25, 2005 Well, you could write some sort of function to do it... EDIT: Yeah, I think I shall remove that code snippet for now. It's horrible Share this post Link to post Share on other sites More sharing options...
oldfett Posted May 25, 2005 Posted May 25, 2005 What you could do is store all the information to an apstring or something and then use the string.length() craption to get the length. Then only print a lines worth and then go to the next line with a for loop. Input the whole sentence into the string using the getline function or else this will just flop. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted May 26, 2005 Posted May 26, 2005 Moo, how's about this one... void printww(char *text) { int conWidth = 80; int i = 0, j = 0; int strLen = 0; int sub = 0; char *cpyText, *start, *tmp, *searchPoint; strLen = strlen(text); if (strLen > conWidth) { cpyText = (char *)malloc(strLen * sizeof(char)); assert(cpyText != NULL); memcpy(cpyText, text, strLen); cpyText[strLen] = '\0'; tmp = cpyText; for (i = conWidth; i < strLen; i += conWidth) { if (cpyText[i - 1] != ' ') { searchPoint = &cpyText[i - 1]; // find previous space sub = 0; start = NULL; for (j = 0; j <= i; j++) { if (*(searchPoint - j) == ' ') { start = (searchPoint - j); break; } sub++; } // start is too long, set start to searchPoint to continue if (start == NULL) { start = searchPoint; } else { // speshulness;-) i -= sub; // stick the whole word on new line *start = '\n'; } // search again from the current word (just after the new \n) tmp = (start + 1); } } printf("%s", cpyText); } else { printf("%s", text); } } I'm going to sleep now Share this post Link to post Share on other sites More sharing options...
cchalogamer Posted May 26, 2005 Posted May 26, 2005 Yeah humm markie's look's a little more complecated than the Java version i coded back in Feb. or March. Can't remember when, but eitherway it looks like it gets the job done....It's amazing how close so many languages are to each other, I can read diff coding languages, yet true == ((me + Spanish) != good) Yeah well looks like markie saved the day so cya later. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted May 26, 2005 Posted May 26, 2005 I wouldn't mind seeing the Java thing you did. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now