title: How do I align a number like this in C?
body: <p>I need to align a series of numbers in C with <strong>printf()</strong> like this example:</p>
  
  <pre><code>-------1
  -------5
  ------50
  -----100
  ----1000
  </code></pre>
  
  <p>Of course, there are numbers between all those but it's not relevant for the issue at hand... Oh, consider the dashes as spaces, I used dashes so it was easier to understand what I want.</p>
  
  <p>I'm only able to do this:</p>
  
  <pre><code>----1---
  ----5---
  ----50--
  ----100-
  ----1000
  </code></pre>
  
  <p>Or this:</p>
  
  <pre><code>---1
  ---5
  --50
  -100
  1000
  </code></pre>
  
  <p>But none of this is what I want and I can't achieve what is displayed on the first example using only printf(). Is it possible at all?</p>
  
  <p><strong>EDIT:</strong><br>
  Sorry people, I was in a hurry and didn't explain myself well... My last example and all your suggestions (to use something like "%8d") do not work because, although the last number is 1000 it doesn't necessarily go all the way to 1000 or even 100 or 10 for that matter.</p>
  
  <p>No matter the number of digits to be displayed, I only want 4 leading spaces at most for the largest number. Let's say I have to display digits from 1 to 1000 (A) and 1 to 100 (B) and I use, for both, "%4d", this would be the output:</p>
  
  <p><strong>A:</strong></p>
  
  <pre><code>---1
  ....
  1000
  </code></pre>
  
  <p>Which is the output I want...</p>
  
  <p><strong>B:</strong></p>
  
  <pre><code>---1
  ....
  -100
  </code></pre>
  
  <p>Which is not the output I want, I actually want this:</p>
  
  <pre><code>--1
  ...
  100
  </code></pre>
  
  <p>But like I said, I don't know the exact number of numbers I have to print, it can have 1 digit, it can have 2, 3 or more, the function should be prepared for all. And I want four extra additional leading spaces but that's not that relevant.</p>
  
  <p><strong>EDIT 2:</strong>
  It seems that what I want, the way I need it, it's not possible (check David Thornley and Blank Xavier answers and my comments). Thank you all for your time.</p>