title: ANSI C UTF-8 problem
body: <p>First I develope an independent platform library by using  ANSI C (not C++ and any non standard libs like MS CRT or glibc, ...).</p>
  
  <p>After a few searchs, I found that one of the best way to internationalization in ANSI C, is using UTF-8 encoding.</p>
  
  <p>In utf-8:</p>
  
  <ul>
  <li>strlen(s): always counts the number of <strong>bytes</strong>.</li>
  <li>mbstowcs(NULL,s,0): The number of <strong>characters</strong> can be counted.</li>
  </ul>
  
  <p>But I have some problems when I want to random access of elements(characters) of a utf-8 string.</p>
  
  <p>In ASCII encoding:</p>
  
  <pre><code>char get_char(char* assci_str, int n)
  {
    // It is very FAST.
    return assci_str[n];
  }
  </code></pre>
  
  <p>In UTF-16/32 encoding:</p>
  
  <pre><code>wchar_t get_char(wchar_t* wstr, int n)
  {
    // It is very FAST.
    return wstr[n];
  }
  </code></pre>
  
  <p>And here my problem in UTF-8 encoding:</p>
  
  <pre><code>// What is the return type?
  // Because sizeof(utf-8 char) is 8 or 16 or 24 or 32.
  /*?*/ get_char(char* utf8str, int n)
  {
    // I can found Nth character of string by using for.
    // But it is too slow.
    // What is the best way?
  }
  </code></pre>
  
  <p>Thanks.</p>