title: Format a string using sprintf in c
body: <p>I am using sprintf for string formation in C.</p>
  
  <p>I need to insert '+' and '-' sign before float value.</p>
  
  <p>This positive and negative signs are inserted by checking a flag after that i insert the float value.</p>
  
  <p>Now i want to make this whole number in right alignment along with positive or negative sign.</p>
  
  <p>Currently this is my formatted string:</p>
  
  <pre><code>+300.00
  -200.00
  +34.60
  </code></pre>
  
  <p>I want output like following,</p>
  
  <pre><code>+300.00
  +233.45
   -20.34
  </code></pre>
  
  <p>I have written following code:</p>
  
  <pre><code>char printbuff[1000], flag = 1;
  double temp=23.34, temp1= 340.45;   
  
  sprintf(printBuff, "%c%-lf\n%c%-lf",
          (Flag == 1) ? '+' : '-',
          temp,
          (Flag == 1) ? '+'  :'-',
          temp1);
  </code></pre>
  
  <p>I am getting following output:</p>
  
  <pre><code>+23.34
  +340.45
  </code></pre>
  
  <p>Instead of the desired:</p>
  
  <pre><code> +23.45
  +340.45
  </code></pre>
  
  <p>How can I do this?</p>