How to display the value of a query in C?

-1

Remaining the question:

I have a table in Mysql where I need to display the person's name as soon as they type their RG. I am making a code where I just try to do the search to see if it is fetching normally, but I can not display it on the screen.

Follow the code:

int main(){

    MYSQL conexao;
    int res;
    int esco = 2;
    char query[100];
    mysql_init(&conexao);
    if ( mysql_real_connect(&conexao, "localhost", "root", "", "teatro", 0, NULL, 0) ){
        sprintf(query,"select tb_aluno_nome from tb_aluno where tb_aluno_rg = '999999999';");
        res = mysql_query(&conexao,query);
        if (!res)
            printf("nome: %i",res);
        system("pause");
        return(0);

    }
}
    
asked by anonymous 04.11.2018 / 22:37

1 answer

0

Test my good!

int main() {
   MYSQL conexao;
   int res;
   int esco = 2;
   char query[100];
   mysql_init(&conexao);
   if ( mysql_real_connect(&conexao, "localhost", "root", "", "teatro", 0, NULL, 0) ){
       sprintf(query, "select tb_aluno_nome from tb_aluno where tb_aluno_rg = '999999999';");
       res = mysql_query(&conexao,query);
       if (res) {
           campos = mysql_fetch_fields(res);
           for (i=0; i < mysql_num_fields(res); i++) {
               printf("%s", (campos[i]).name);
           }
       }
   }
   mysql_close(&conexao);
   system("pause");
   return(0);
}
    
06.11.2018 / 16:36