LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2012, 04:34 PM   #1
ali2011
Member
 
Registered: Nov 2011
Location: USA, CA
Distribution: Ubuntu+Fedora
Posts: 80

Rep: Reputation: Disabled
Printf Alignment:


Is it possible to force printf in C to print a large file, from which the following is a cut to make the last column aligned as below?

PS: The lines in the file are printed line-by-line in the code.

The current printf result:
Quote:
1 104 101 37 [3]
1 25 111 [2]
1 25 58 117 [3]
1 25 58 46 126 148 123 [6]
1 25 58 46 126 [4]
1 152 129 [2]
1 25 58 143 [3]
The goal is:
Quote:
1 104 101 37 [3]
1 25 111 [2]
1 25 58 117 [3]
1 25 58 46 126 148 123 [6]
1 25 58 46 126 [4]
1 152 129 [2]
1 25 58 143 [3]

For some reason the last column in the goal file is not aligned as required when I post the file as a code; anyhow, I look for number in between the square brackets to be aligned throughout the file.

Last edited by ali2011; 07-12-2012 at 04:45 PM.
 
Old 07-12-2012, 04:38 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please re-think and re-state your question.
 
Old 07-15-2012, 02:44 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by ali2011 View Post
Is it possible to force printf in C to print a large file, from which the following is a cut to make the last column aligned as below?

PS: The lines in the file are printed line-by-line in the code.

The current printf result:


The goal is:
Look at something like printf("%10s", variable)

Quote:
Originally Posted by ali2011 View Post
For some reason the last column in the goal file is not aligned as required when I post the file as a code; anyhow, I look for number in between the square brackets to be aligned throughout the file.
Paste the output between code tags ([code] and [/code]) instead of between quote tags ([quote] and [/quote]).

Code:
  1  2  3
 11 12 13

Last edited by Wim Sturkenboom; 07-15-2012 at 02:46 AM.
 
Old 07-15-2012, 07:53 AM   #4
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
Smile

1st, man printf, then you can know many format informations about it. (so you can know how to display with many different and useful ways)

2nd, when output, you can calculate the location firstly, and then output it (so you can control the detail locations)

That is all.

: )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Data alignment, mantu55 Linux - Software 2 05-25-2012 04:21 AM
RAID6 I/O and Alignment aviso Linux - Server 0 08-16-2009 12:29 PM
Data Alignment nesta Programming 6 05-01-2007 01:22 PM
about alignment eshwar_ind Programming 5 10-18-2004 08:27 AM
glabels alignment Spaz17 Linux - Software 1 11-28-2003 01:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration