Putting Whitespaces and newlines

Thread Solved

Join Date: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

Putting Whitespaces and newlines

 
0
  #1
Jan 19th, 2008
Does anyone know how to put a whitespace or a newline in a .txt file???

By this I mean, I have this long string, and I have to put whitespaces and new lines to make it understandable.

To summarize, I just want to know what functions will be effective to do this
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
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: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Putting Whitespaces and newlines

 
0
  #2
Jan 19th, 2008
Need an example. you want to change "WethePeopleoftheUnitedStates" to this: "We the People of the United States" ? If the text is in a file then you will have to completly rewrite the file. First open the original file for reading, then another file for writing. In a loop read a line, modify it in memory as desired, then write the modified string to the output file.

Problem: how do you know where to add the spaces and new lines ?
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: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

Re: Putting Whitespaces and newlines

 
0
  #3
Jan 19th, 2008
Sorry about that, but yes, that is my problem.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
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: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Putting Whitespaces and newlines

 
0
  #4
Jan 19th, 2008
Originally Posted by gallantmon1 View Post
Sorry about that, but yes, that is my problem.
If this is schoolwork then your teacher should tell you how to do it. Otherwise, its nearly impossible for a program to check a string and add spaces where necessary to make it understandable to a human reader. You need to get more information from whoever gave you the requirements for the program.
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: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

Re: Putting Whitespaces and newlines

 
0
  #5
Jan 19th, 2008
The input is this "mova,badda,b" and I have to turn it into this:

mov a, b
add a, b

The program doesn't have to be flexible, because there is a given string. My problem is as you said how can I know where to put it
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
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: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Putting Whitespaces and newlines

 
0
  #6
Jan 19th, 2008
that should be fairly simple. First find the comma and back up one character. That is where you insert the space. Add another space immediately after the command, and a line feed one character beyone that. Do it with two string arrays -- the first is the original string and the second is the altered string.

I would write it for you, but I don't want to spoil all your fun
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: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

Re: Putting Whitespaces and newlines

 
0
  #7
Jan 20th, 2008
Could you explain the two string arrays further, I'm not that good when it comes to arays, but thanks for the help. At least now I have an idea on how to do it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
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: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Putting Whitespaces and newlines

 
0
  #8
Jan 20th, 2008
>>Could you explain the two string arrays further

You can't use the original string array to insert the spaces for a couple reasons
  • the array may not be large enough to hold the additional characters.
  • the array may be a literal and stored in read-only memory, any attempt to change it would probably crash the program.

So to overcome those problems create another string array that is large enough to hold all the characters in the first plus the additional characters you want to add. Making the second array too large is ok, but too small can be a disaster waiting to happen.
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: Oct 2007
Posts: 34
Reputation: gallantmon1 is an unknown quantity at this point 
Solved Threads: 0
gallantmon1 gallantmon1 is offline Offline
Light Poster

Re: Putting Whitespaces and newlines

 
0
  #9
Jan 20th, 2008
Ok, thanks for the help.

I finally get what your saying.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC