title: How to loop through a byte array in C programming and store in a string as Hexadecimal
body: <p>How to loop through a byte array in C programming and store the hexadecimal output of each byte element in a string as Hexadecimal. I am using VS2005.</p>
  
  <pre><code>int main(int ArgC,char** ArgV)
  {
      char*           string;
      char            stringSHA1[3];
      char*           stringSHA1Final = "";
      Sha1Context     sha1Context;
      SHA1_HASH       sha1Hash;
      uint16_t        i;
  
      string = "Hello World";//ArgV[1];
  
      Sha1Initialise( &amp;sha1Context );
      Sha1Update( &amp;sha1Context, string, (uint32_t)strlen(string) );
      Sha1Finalise( &amp;sha1Context, &amp;sha1Hash );
  
      stringSHA1Final = malloc(sizeof(sha1Hash)*2 + 1);
  
      for( i=0; i&lt;sizeof(sha1Hash); i++ )
      {
          printf( "%2.2x", sha1Hash.bytes[i] );
          sprintf_s(stringSHA1, 5, "%s%02x", "0x", sha1Hash.bytes[i] );
          stringSHA1Final[i] = stringSHA1;
      }
      printf( stringSHA1Final );
  
      return 0;
  }
  </code></pre>
  
  <p>I have trouble in concatenating the hexadecimal string into a single string and return.</p>