c语言中用mysql_row[]取mysql数据库中的值后(数据库中为浮点型),因为取出的值是字符串型(应该是字符串吧,用%S能打印),但我需要将取出的值转为浮点型进行计算处理,字符串无法处理,但不知道怎么转换,用atof函数转换也不正确,恳请高人!!  急~ 谢谢~~

解决方案 »

  1.   

    MYSQL_RES This structure represents the result of a query that returns rows (SELECT, SHOW, DESCRIBE, EXPLAIN). The information returned from a query is called the result set in the remainder of this section. MYSQL_ROW This is a type-safe representation of one row of data. It is currently implemented as an array of counted byte strings. (You cannot treat these as null-terminated strings if field values may contain binary data, because such values may contain null bytes internally.) Rows are obtained by calling mysql_fetch_row(). 根据手册很清楚,MYSQL_ROW 就是一个string, 如果你想处理数据,建议用MYSQL_RES 用mysql_query 执行你的select 然后用 mysql_store_result来处理。网上找个例子参考一下。
      

  2.   

    http://www.unixresources.org/linux/clf/db/archive/00/00/09/81/98199.html
    请看这个帖,数据库数据为整型时取出来用atoi函数转换一下的确可以取出为整型,但浮点型就怎么也变不过去,atof函数也没用。
      

  3.   

    浮点型数据根本就不需要转换
    char c = *mysql_row[i]即可。注意,mysql_row[i]对应的字段必须是浮点型回复2楼的
      

  4.   

    直接处理MYSQL_RES能避免这个问题?
    好像MYSQL_RES就是从MYSQL_RES的data字段中取出来的