title: Convert string array into hex numbers in C
body: <p>I have a file that contains a matrix of many rows and columns. It looks like something below:</p>
  
  <pre><code>fa ff 00 10 00
  ee ee 00 00 30
  dd d1 00 aa 00
  </code></pre>
  
  <p>Each entry in the matrix is a hex number of an eight bit value. I would like to read this file into a two dimensional array. </p>
  
  <p>I have two problems:</p>
  
  <ol>
  <li><p>Using the read method in my code, *it contains an array that has each entry (two characters) of the matrix. How can I pass each entry into a single variable instead of two characters?</p></li>
  <li><p>When I pass into the single variable, how to convert it from character to hex?
  I mean "ff" should be converted to 0xff.</p></li>
  </ol>
  
  <p>Part of my code is below. I can avoid the tokenize function if better methods can be uesd.</p>
  
  <pre><code>char** tokens;
  char** it;
  
  while (fgets(line, sizeof(line), file) != NULL){ /* read a line */
      tokens = tokenize(line);    // split line
  
      for(it=tokens; it &amp;&amp; *it; ++it){
          printf("%s\n", *it);
          free(*it);
      } // end for
  } // end while
  
  char** tokenize(const char* str){
      int count = 0;
      int capacity = 10;
      char** result = malloc(capacity*sizeof(*result));
  
      const char* e=str;
  
      if (e) do {
          const char* s=e;
          e=strpbrk(s," ");
  
          if (count &gt;= capacity)
              result = realloc(result, (capacity*=2)*sizeof(*result));
  
          result[count++] = e? strndup(s, e-s) : strdup(s);
      } while (e &amp;&amp; *(++e));
  
      if (count &gt;= capacity)
          result = realloc(result, (capacity+=1)*sizeof(*result));
      result[count++] = 0;
  
      return result;
  }
  </code></pre>