title: Convert hex char[] to int[] in C 2 chars in 1 byte
body: <p>I am trying to convert a char[] in hexadecimal format to int[] in hexadecimal.</p>
  
  <p>Something like this:</p>
  
  <p>hello --> 68656C6C6F --> [68, 65, 6C, 6C, 6F]</p>
  
  <p>This is my code: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  uint8_t* hex_decode(unsigned char *in, size_t len, uint8_t *out);
  
  int main(void){
  unsigned char  word_in[17], word_out[33];//17:16+1, 33:16*2+1
  int i, len = 0;
  uint8_t* out;
  
  
  while(len != 16){
      printf("Set new word:");
      fgets( word_in, sizeof( word_in), stdin);
      len = strlen( word_in);
      if( word_in[len-1]=='\n')
          word_in[--len] = '\0';
  
      for(i = 0; i&lt;len; i++){
          sprintf(word_out+i*2, "%02X",  word_in[i]);
      }
      if(len != 16){
          printf("Please, use a word of 16 chars long\n\n");
      }
  }
  printf("%s", word_in);
  printf("\n");
  
  hex_decode(word_out, sizeof(word_out), out);
  
  return 0;
  }
  
  uint8_t* hex_decode(unsigned char *in, size_t len, uint8_t *out)
  {
      unsigned int i, t, hn, ln;
  
      for (t = 0,i = 0; i &lt; len; i+=2,++t) {
  
              hn = in[i] &gt; '9' ? (in[i]|32) - 'a' + 10 : in[i] - '0';
              ln = in[i+1] &gt; '9' ? (in[i+1]|32) - 'a' + 10 : in[i+1] - '0';
  
              out[t] = (hn &lt;&lt; 4 ) | ln;
              printf("%s",out[t]);
      }
      return out;
  
  }
  </code></pre>
  
  <p>But after printing the word, I got a segmentation fault.</p>
  
  <p>That function works perfect in arduino so I think it should works fine at my computer... Where is the problem?</p>