title: C - printf() not working correctly?
body: <p>I'm writing a simple program which takes data about people in this format:
       name,age,gender,info</p>
  
  <p>and it will display them like this
       [name: , age: , gender: , info: ]</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  char name[10];
  int age;
  char gender[2];
  char info[50];
  
  while(scanf("%9[^,],%i,%c,%49[^\n]", name, &amp;age, gender, info) == 4) {
      printf("[name: %s, age: %i, gender: %c, info: %s]\n", name, age, gender, info);
  }
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>So I decided to write my output to another text file using >. And it does nto display correctly, the ] bracket displays on a new line and [name: by itself.</p>
  
  <p>This is my input:</p>
  
  <pre><code> eliza,7,F,likes animals
   bob,9,M,fast at running
   sue,6,F,likes painting
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre><code> [name: eliza, age: 7, gender: J, info: likes animals
   ]
   [name: 
   bob, age: 9, gender: J, info: fast at running
   ]
   [name: 
   sue, age: 6, gender: J, info: likes painting
   ]
  </code></pre>
  
  <p>Can someone help? I can't figure out why it prints the data like this, I tried using strstr() to check if any of my variables contained the new line character.</p>