title: Strange length and content of a char array based on another one in C
body: <p>I have a char array filled with letters and blanks (maximum length of 100) and I want to create another char array with the same length. This new array should contain a blank at a certain positions, if there's a blank in the original array, and a '#' if there's a letter. 
  I need this for a hangman game in c and solved it this way:</p>
  
  <pre><code>//the original array is in a structure (with other char arrays)
  //struct entry{
  //char expression[100];
  //....
  //};
  
  //which an array of called dictionary is created and filled later (this works)
  
  
  
  //now the part where it somehow fails:
  
  //figure out the length of the string in the first char array
  int oldlength = strlen(dictionary[index].expression);
  
  //create the new array (same length) and set its memory to 0 (doesn't actually matter)
  char newexp[oldlength];
  memset(newexp, 0, oldlength * sizeof(char));
  
  //fill this new array as described
  for(int i = 0; i &lt; oldlength; i++)
  {
      if(dictionary[index].expression[i] == ' ')
      {
          newexp[i] = ' ';
      }
      else
      {
          newexp[i] = '#';
      }
  }
  </code></pre>
  
  <p>Now I thought that this new array would work just the way i wanted it to. It sometimes does and my hangman game works completley fine in this cases. But sometimes it seems to make the new array longer than the old one and add weird characters (or maybe it's just the weird output of empty space (?)).</p>
  
  <p>Now my way of testing this was:</p>
  
  <pre><code>printf("Expression in struct: %s\n", dictionary[index].expression);
  printf("Length of expression in struct: %d\n", oldlength);
  printf("Expression afterwards in new array: %s\n", newexp);
  printf("Length of expression in new array: %d\n", strlen(newexp)); //I know, int != size_t
  </code></pre>
  
  <p>Now sometimes the game works and the output is something like :</p>
  
  <pre><code>Expression in struct: wonderful
  Length of expression in struct: 9
  Expression afterwards in new array: #########     //9x '#'
  Length of expression in new array: 9
  </code></pre>
  
  <p>Note: The "//9x '#'" isnt in the output, I just counted them for faster understanding (same in the next examples)</p>
  
  <p>But sometimes it give out stuff like this (actual, german example):</p>
  
  <pre><code>Expression in struct: glaesarn
  Length of expression in struct: 8
  æ@pression afterwards in new array: ########     //yes, 8x '#'
  Length of expression in new array: 11
  </code></pre>
  
  <p>In this example I also give out the second array another time later and it says:</p>
  
  <pre><code>æ@######     //6x '#' ?
  </code></pre>
  
  <p>Tried it a few time... sometimes there's these two letters added at the beginning.. sometimes it's some other stuff at the end:</p>
  
  <pre><code>//another example
  
  Expression in struct: Moebelrolle
  Length of expression in struct: 11
  æ@pression afterwards in new array: ######### ░h=v        i=væÚ7v     //9x '#' ?
  Length of expression in new array: 27
  
  //and later the arrays gives out
  æ@######### ░h=v        i=væÚ7v     //9x '#'?
  </code></pre>
  
  <p>I don't understand how these two arrays can suddenly have such a different length (there's no other simultaneous access to it) and I thought this code to be relatively simple.
  It also kinda boggles my mind how the output of "Expression afterwards" becomes "æ@pression afterwards"... how is this even possible ?</p>