c++ - How to populate an array of struct from an sqlite3 query? -


i working on native winapi application using cpp , sqlite. have simple listbox in window populate values sqlite table have following sqlite query c++ code:

    sqlite3 * db = null;     sqlite3_stmt * stmt;     int i, db_qry;     const char * tail;     const char * sqlselect  = "select * my_friends";     db_qry = sqlite3_open("friends.db", &db);    if(sqlite3_prepare(db, sqlselect, -1, &stmt, &tail) == sqlite_ok)    {      while(sqlite3_step(stmt) != sqlite_done)      {         for(i = 0; < sqlite3_column_count(stmt); i++) {             const unsigned char * p =  reinterpret_cast<const unsigned char *>                     (sqlite3_column_text(stmt, 0));             const char * finaltext = (const char *)p;             //method poulating listbox somewhere             addstringlist(hlist,_t(finaltext));             }         }        sqlite3_finalize(stmt);        }    sqlite3_close(db); 

based on loop used in sqlite query use, need on how can populate array of structs this:

typedef struct {     wchar_t name[30];      wchar_t job[20];      int age;   } friends;   friends friends[] = {      {l"lucy", l"waitress", 18},      {l"thomas", l"programmer", 25},      {l"george", l"police officer", 26},      {l"michael", l"producer", 38},      {l"jane", l"steward", 28},  };  

i had ask question here because dont have idea of how can generate values of array inside loop.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -