title: best way to store data from mysql result using C
body: <p>My C programming is decidedly rusty:-(</p>
  
  <p>I have studied <a href="http://zetcode.com/db/mysqlc/" rel="nofollow">http://zetcode.com/db/mysqlc/</a> and essentially comfortable with it.</p>
  
  <p>But I am unsure of the best way of storing the data retrieved.</p>
  
  <pre><code>  int num_fields = mysql_num_fields(result);
    MYSQL_ROW row;
    while ((row = mysql_fetch_row(result))) {
    for(int i = 0; i &lt; num_fields; ) {
      printf("%s ", row[i] ? row[i] : "NULL"); 
    } 
    printf("\n"); 
  </code></pre>
  
  <p>this works fine and give me exactly the correct results.</p>
  
  <p>Being familiar with perl hashes, I am tempted to use a C structure.  Each record in my (small) database consists of different types of columns: char, float, int etc.</p>
  
  <p>So I have:</p>
  
  <pre><code>    struct Parameter {
        char  name[LEN_NAME];
        float max;
        float min;
        float sample_interval;
        int active;
        char units[LEN_UNITS];
        char start[LEN_START];
        char start_time[LEN_START_TIME];
        char end[LEN_END];
        char end_time[LEN_END_TIME];
        char type[LEN_TYPE];
      };  
      struct Parameter parameters[MAX_PARAMETERS];
  </code></pre>
  
  <p>Where the LENs are defined constants.</p>
  
  <p>I am trying things like:</p>
  
  <pre><code>    num_fields = mysql_num_fields(result);
      int r = 0;
      while ((row = mysql_fetch_row(result))) {
      for(int i = 0; i &lt; num_fields; i++) {
        printf("%s ", row[i] ? row[i] : "NULL");
        sscanf(row[0], "%LEN_NAMEs",  parameters[r].name);
        sscanf(row[1], "%d",      &amp;parameters[r].max);
  </code></pre>
  
  <p>Which seems to be working OK for the chars, but not for the other types.</p>
  
  <p>Struggling.  Perhaps I am up a gum tree!</p>