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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
gplanaCommented:
instead of
type[0] = row[1]

try
strcpy(stype,row[1])
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lulonAuthor Commented:
worked!! Thanks!

strcpy(type, row[1])
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.