The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Aligning data in .txt file
Discuss Aligning data in .txt file in the C Programming forum on Dev Shed. Aligning data in .txt file C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 13th, 2004, 02:52 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Aligning data in .txt file
How to align my data to display nicely in a text file?? Some of the data are out of alignment.. How to get them back in place?
Characters Segment
========== =======
dynamic labels m 10
ay also contain 00
special characte 00
rs, such as the 00
german ΡΧΩ 00
and the like 01
End of header
pr 10
eferred line bre 00
ak
again
preferr 00
ed word break af 00
ter the second ' 00
4': 123456789012 00
34567890 01
Single DLS 11
Single DLS 11
Single DLS 11
Single DLS 11
Single DLS 11
A somehow longer 10
A somehow longer 10
|

August 13th, 2004, 05:09 AM
|
 |
Lord of Dorkness
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
You apparently have gratuitous newline codes sprinkled throughout.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.
|

August 13th, 2004, 05:31 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
The forum has removed all multiple whitespace and rendered the illustration of your problem useless.
You should use code tags for the example text output.
How are you outputting the text; with iostream or stdio?
Both stdio and iostream allow field widths and left/right justification to be specified. Something like:
Code:
fprintf( "%-30s%2.2X", characters, segment ) ;
will pad the string characters to exactly 30 characters with spaces, and display the integer segment as two hex digits.
Similar things can be done with iostream using the setw I/O manipulator: http://www.cplusplus.com/ref/iostream/iomanip/setw.html
Clifford
|

August 13th, 2004, 08:52 AM
|
 |
ASP.Net MVP
|
|
Join Date: Aug 2003
Location: WI
|
|
|
The thing about text files is that different editors can display them with different fonts. Even if you're audience consists entirely of windows sheep running only notepad many of them may have a different system font set. You also have to take into account fixed width vs variable width fonts. You can get it looking right on your system, but remember that this may not hold everywhere.
That said, look into the iomanip library and setw() functions.
|

August 13th, 2004, 08:57 AM
|
 |
I'm Baaaaaaack!
|
|
Join Date: Jul 2003
Location: Maryland
|
|
|
Baaaaaa!
|

August 13th, 2004, 09:01 AM
|
 |
ASP.Net MVP
|
|
Join Date: Aug 2003
Location: WI
|
|
|
mitakeet looks a bit sheepish. Truth be told I haven't been in anything but windows for a month or so myself. I keep going back to play tactical ops.
|

August 13th, 2004, 09:10 AM
|
 |
I'm Baaaaaaack!
|
|
Join Date: Jul 2003
Location: Maryland
|
|
|
In little bit to my defense, I work with *nix almost all day at work, but they took away our Sunrays and we have to ssh to the machines from our PC to do work. I used to have RH 8 installed on a machine at home, but rebuilt that as Win2K. My excuse? At the time I could not get the machine to talk to the 'net past my proxy. Since then I have switched to a DSL router and should not have problems, but have been too lazy.
|

August 13th, 2004, 03:24 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
ok i think i have done it using the code clifford provide... thanks alot!!!!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|