title: what is the correct way to get strlen for a unsigned char *
body: <p>My code below gave a different length for the unsigned char pointer I expect.
  I thought I should be getting 12 (or 13) or 0 (or 1) for pph and pphChar.
  What is my problem?  I got different results for length and oneLength each time, when I repeat the run.</p>
  
  <p>How can I get the length of pph?</p>
  
  <p>Do I need to put a '\n' at the end to determine the length?</p>
  
  <p>I use VS2010, XP and C++.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;stdlib.h&gt;
  #include &lt;Windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  
  typedef unsigned char uint8_t;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
  
  int length;
  int len = 13;
  uint8_t *phh;
  char * phhChar;
  
  printf("assigned mem %d\n", sizeof(unsigned char)*len);
  phh = (unsigned char *) malloc(sizeof(unsigned char)*len);
  phhChar = (char *) malloc(sizeof(char)*len);
  
  phh[0] = (unsigned char) '1';
  phh[1] = (unsigned char) '2';
  phh[2] = (unsigned char) '3';
  phh[3] = (unsigned char) '4';
  phh[4] = (unsigned char) '5';
  phh[5] = (unsigned char) '6';
  phh[6] = (unsigned char) '7';
  phh[7] = (unsigned char) '8';
  phh[8] = (unsigned char) '9';
  phh[9] = (unsigned char) '0';
  phh[10] = (unsigned char) '1';
  phh[11] = (unsigned char) '2';
  phh[12] = (unsigned char) '\n';
  
  phhChar[0] = (char) '\n';
  
  printf("size of char %d\n", sizeof(unsigned  char));
  length =  strlen((const char*)phh);
  int oneLength = strlen((const char*)phhChar);
  
  printf("len %d\n", length );
  printf("onelebgth %d\n", oneLength);
  </code></pre>
  
  <p>OUTPUT</p>
  
  <p>assigned mem 13</p>
  
  <p>size of char 1</p>
  
  <p>len 32  - different each time</p>
  
  <p>oneLength 32 - different each time</p>