get a char from a mysql query

Hello,

If this is the table:

table
------------------
cod int
type char
name varchar(30)



I'm having problems when trying to get the char column:

#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>

***
char query[1024]= "SELECT code, type, name FROM table WHERE code=1";
MYSQL *conn;
conn= getConnection();
mysql_query(conn, query);
MYSQL_RES *res= mysql_use_result(conn);
MYSQL_ROW row= mysql_fetch_row(res);
int cod= atoi(row[0]);
char type= row[1];
***

Does it need any converstion?

Thanks in advance.
lulonAsked:
Who is Participating?
 
gplanaCommented:
instead of
type[0] = row[1]

try
strcpy(stype,row[1])
0
 
gplanaCommented:

What character set are these fields using ? If using UTF16, you will have an extra 0 for every ascii code, so C will detect end of string.

Also, try to use char[1] instead of char on your C program, as char SQL datatype is referred to a string, such as varchar.

Hope it helps.
0
 
lulonAuthor Commented:
This Mysql is set with UTF-8 Unicode.




I'm trying this...

***
char query[1024]= "SELECT code, type, name FROM table WHERE code=1";
MYSQL *conn;
conn= getConnection();
mysql_query(conn, query);
MYSQL_RES *res= mysql_use_result(conn);
MYSQL_ROW row= mysql_fetch_row(res);
int cod= atoi(row[0]);
char type[1];
type[0]= row[1];
***



I'm getting this warning while compiling:
warning: assignment makes integer from pointer without a cast


And when executing, type gets values like '[' or '^'
0
 
lulonAuthor Commented:
worked!! Thanks!

strcpy(type, row[1])
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.