title: WHy does this code crash, when used with bin?
body: <p>As the title suggests, I don't know where my mistake is with binary.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char binary[360];
  
  void printstringasbinary(char* s)
  {
      // A small 9 characters buffer we use to perform the conversion
      char output[9];
  
      while (*s)
      {
          // Convert the first character of the string to binary using itoa.
          // Characters in c are just 8 bit integers, at least, in noawdays computers.
  
          itoa(*s, output, 2);
  
          strcat(binary, output);
  
          ++s;
      }
  
  }
  
  int main(int argc, char *argv[])
  {
  
      int i, n;
  
      //printf("argc: %i\n", argc);
      if (argc != 3)
      {
          puts("Converter [Text] [hex|dec|bin]");
          return 0;
      }
      FILE *f = fopen("Output.txt", "a");
      for (i = 0; i &lt; strlen(argv[0]); i++)
      {
          if (strcmp(argv[2], "hex") == 0)
              fprintf(f, "%X ", (unsigned int) argv[1][i]);
          else if (strcmp(argv[2], "dec") == 0)
              fprintf(f, "%i ", (unsigned int) argv[1][i]);
          else if (strcmp(argv[2], "bin") == 0)
              for (n = 0; n &lt; strlen(argv[1]); n++)
              {
                  printstringasbinary(argv[1][i]);
              }
          fprintf(f, "%s ", binary);
  
      }
      fclose(f);
  
      return 0;
  }
  </code></pre>