title: Simple use of sprintf - C
body: <p>I'm trying to work out why a larger problem is occurring, using a smaller program as an example. This smaller program does not work, leading me to believe it is my understanding of the function that is flawed.</p>
  
  <p>As far as I (had) believed, the following program should initialise a string with up to 30 characters, then take the number '5' to nine significant figures, and turn it into that string. The program should then print the value '5.00000000'. However, the program prints the value 7.96788(...). Why is this?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      char word[30];
      sprintf(word, "%.9g", 5);
      printf(word);
      return 0;
  }
  </code></pre>