title: not able to printf output of a function returning an array pointer in C
body: <p>I'm trying to create a function that converts a hex string into an array of hex bytes. Example: <code>str = &quot;1c01&quot;</code> -&gt; <code>hex_bytes = { 0x1c, 0x01 }</code>.</p>
  <p>When I try to print the hex values all I get are 0s. I'm thinking it's something to do with my pointers but I am not sure. Any help would be greatly appreciated.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  const char *input_1 = &quot;1c0111001f010100061a024b53535009181c&quot;;
  
  unsigned int *str_to_hexbytes(const char *hex_str) {
      size_t len = strlen(hex_str);
      unsigned int *hex = malloc(sizeof(unsigned int)* len / 2);
      for(int i, j = 0; i &lt; len; i += 2, j++) {
          char tmp[2];
          strncpy(tmp, hex_str + i, 2);
          hex[j] = strtol(tmp, NULL, 16);
      }
      return hex;
  }
  
  int main(void) {
      size_t len = strlen(input_1) / 2;
      unsigned int *hex = str_to_hexbytes(input_1);
      for (int i = 0; i &lt; len; i++) {
          printf(&quot;%x &quot;, hex[i]);
      }
      return 0;
  }
  </code></pre>