title: How to store an ascii value of 0 in a character string without terminating it?
body: <p>Taking an input as hex string and then converting it to char string in C. The hex string can contain 0x00 which translates to an 0 in Ascii when converted. This terminates the string. I have to store the value in an char string because the API uses that.<br>
  My code so far:</p>
  
  <pre><code>int hex_to_int(unsigned char c) {
      int first =0;
      int second =0;
      int result=0;
      if(c&gt;=97 &amp;&amp; c&lt;=102)
          c-=32;
      first=c / 16 - 3;
      second =c % 16;
      result = first*10 + second;
      if(result &gt; 9) result--;
          return result;
  }
  unsigned char hex_to_ascii(unsigned char c, unsigned char d){
      unsigned char a='0';
      int high = hex_to_int(c) * 16;
      int low = hex_to_int(d);
      a= high+low;
      return a;
  }
  unsigned char* HextoString(unsigned char *st){
      int length = strlen((const char*)st);
      unsigned char* result=(unsigned char*)malloc(length/2+1);
      unsigned char arr[500];
      int i;
      unsigned char buf = 0;
      int j=0;
      for(i = 0; i &lt; length; i++)
      {
          if(i % 2 != 0)
      {
          arr[j++]=(unsigned char)hex_to_ascii(buf, st[i]);
      }
      else
      {
           buf = st[i];
      }
      }
      arr[length/2+1]='\0';
      memcpy(result,arr,length/2+1);
      return result;
  }
  </code></pre>