将char *转换为标准C中的float/int [英] Convert char* to float / int in standard C
问题描述
我正在使用纯C语言编写程序,我想知道如何将char*
转换为float
/int
.我知道ato?
函数,但我所期望的还不止于此.我正在寻找int str2float(char*, float*)
/int str2int(char*, int*)
之类的函数,它们会返回给定的char*
是否可以是合法的数字格式.
如果将普通的"0.0"
或"something_else"
传递给atof
,我会得到一个0.0
;如果我将"3.14"
或"3.14balabala"
传递给它,则会得到一个3.14
,那将是非常糟糕的对我来说.
Hi,
I''m working on a program in pure C, and I''m wondering how could I convert a char*
to float
/ int
. I know the ato?
functions but what I expect is more than that; I''m looking for functions maybe like int str2float(char*, float*)
/ int str2int(char*, int*)
which they return whether the given char*
could be a legal numeric format.
I would get a 0.0
if I passed a normal "0.0"
or a "something_else"
to atof
, and get a 3.14
if I passed a "3.14"
or a "3.14balabala"
to it, that would be terrible for me.
推荐答案
请参阅这些 [ ^ ]函数,我认为他们会按照您的要求去做.
See these[^] functions, I think they will do what you are asking.
这篇关于将char *转换为标准C中的float/int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!