Newbie string problem

Reply

Join Date: May 2005
Posts: 56
Reputation: Prahaai is an unknown quantity at this point 
Solved Threads: 0
Prahaai's Avatar
Prahaai Prahaai is offline Offline
Junior Poster in Training

Newbie string problem

 
0
  #1
Nov 14th, 2006
Hello. I have this problem:

I have a let's say [1000] char string and i want to split and print this on the screen on more lines, so that each and every line has MAXIM 43 characters. The string may contain spaces and the words would be printed on the next line if they cant fit on the current line...

I have no idea how to do that. I know how to show the letters from, lets say [100] to the end of the string, with StringName+100, but how can i show the string from 100 to 143?...

Thank you in advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Newbie string problem

 
0
  #2
Nov 14th, 2006
you will need a second char array. copy the first 43 characters to this second char array array then print it. then print the remainder of the original array.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: Newbie string problem

 
0
  #3
Nov 14th, 2006
Use counter which will print the chars.
  1. for(i=0; i<totalLengthOfString; i++)
  2. {
  3. if(i != 0 && i % MAXIM == 0)
  4. {
  5. putchar('\n');
  6. }
  7. putchar(string[i]);
  8. }
The second question also can solve with counter.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Newbie string problem

 
0
  #4
Nov 14th, 2006
Originally Posted by andor View Post
Use counter which will print the chars.

The second question also can solve with counter.
Yes, that is a better solution than mine -- doesn't require a second buffer.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 56
Reputation: Prahaai is an unknown quantity at this point 
Solved Threads: 0
Prahaai's Avatar
Prahaai Prahaai is offline Offline
Junior Poster in Training

Re: Newbie string problem

 
0
  #5
Nov 14th, 2006
Thank you very much, the idea is EXCELLENT.

(I had to include ostream for it to work. :p)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC