title: C formatted string - How to add leading zeros to string value using sprintf?
body: <p>I want to add zeroes at the starting of a string. I am using format specifier.
  My input string is <code>hello</code>
  I want output as <code>000hello</code>.</p>
  
  <p>I know how to do this for integer.</p>
  
  <pre><code>int main()
  {
      int i=232;
      char str[21];
      sprintf(str,"%08d",i);
  
      printf("%s",str);
  
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>OUTPUT will be -- 00000232</p>
  </blockquote>
  
  <p>If I do the same for string.</p>
  
  <pre><code> int main()
      {
          char i[]="hello";
          char str[21];
          sprintf(str,"%08s",i);
  
          printf("%s",str);
  
          return 0;
      }
  </code></pre>
  
  <blockquote>
    <p>OUTPUT will be -    hello (with 3 leading space)</p>
  </blockquote>
  
  <p>Why it is giving space in case of string and zero in case of integer?</p>