一文搞懂:_itoa_itow_itotatoiatofatol

简介: 一文搞懂:_itoa_itow_itotatoiatofatol

"

函数原型:

char _itoa( int value, char string, int radix ); //ANSI

wchar_t _itow( int value, wchar_t string, int radix );//UNICODE

_itot 只是一个宏,根据系统定义的字符集来去_itoa或者_itow, 对应的安全函数为_itot_s

说明:把int 转化为字符串,value为被转化的值,string为转化的目的字符串, radix为基数必须在2到36之间.

所需头文件 #include

举例说明:这里用它们的安全函数: _itoa_s _itow_s

char szYearA【5】 = {0};

WCHAR szYearW【5】 = {0};

_itoa_s(100, szYearA, 10);

_itow_s(100, szYearW, 10);

atoi atof atol

Convert strings to double (atof), integer (atoi, _atoi64), or long (atol).

double atof( const char *string );

int atoi( const char *string );

_int64 _atoi64( const char *string );

long atol( const char *string );

举例:

double d1 = atof(""sa34""); //代码效果参考:https://v.youku.com/v_show/id_XNjQwMDQwMjMxNg==.html

//d1 = 0.00000000000000000

double d2 = atof(""34gdf""); //d2 = 34.000000000000000

double d3 = atof(""-0343""); //d3 = -343.00000000000000

double //代码效果参考:https://v.youku.com/v_show/id_XNjQwNjg1NDM2OA==.html

d4 = atof(""008""); //d4 = 8.0000000000000000

int i1 = atoi(""df""); //i1 = 0

int i2 = atoi(""54.34""); //i2 = 54

int i3 = atoi(""-54""); //i3 = -54

int i4 = atoi(""09""); //i4 = 9


"
image.png
相关文章
|
C语言
【C语言】atoi函数的使用和模拟实现
本篇将介绍atoi函数的使用,通过实例讲解函数的使用方法,模拟实现atoi函数。
129 1
|
12月前
|
C语言
【c语言】atoi的模拟实现
【c语言】atoi的模拟实现
47 0
|
21天前
|
存储 Serverless C语言
【C语言基础考研向】11 gets函数与puts函数及str系列字符串操作函数
本文介绍了C语言中的`gets`和`puts`函数,`gets`用于从标准输入读取字符串直至换行符,并自动添加字符串结束标志`\0`。`puts`则用于向标准输出打印字符串并自动换行。此外,文章还详细讲解了`str`系列字符串操作函数,包括统计字符串长度的`strlen`、复制字符串的`strcpy`、比较字符串的`strcmp`以及拼接字符串的`strcat`。通过示例代码展示了这些函数的具体应用及注意事项。
|
4月前
|
算法 C语言
【C语言】:atoi函数的使用及其模拟实现
【C语言】:atoi函数的使用及其模拟实现
28 5
|
12月前
|
C语言
了解C语言中的atoi函数和模拟实现
了解C语言中的atoi函数和模拟实现
|
12月前
|
Go
Go语言strconv不会? 字符串转换直看这里
Go语言strconv不会? 字符串转换直看这里
41 0
|
编译器 C语言
【C语言进阶】字符函数及字符串函数,带你掌握核心用法并模拟实现(1)——strlen,strcpy,strcmp
【C语言进阶】字符函数及字符串函数,带你掌握核心用法并模拟实现(1)——strlen,strcpy,strcmp
130 1
itoa随手记(itoa是什么,itoa怎么用)
itoa随手记(itoa是什么,itoa怎么用)
124 0
C语言【atoi函数】
看到atoi函数,有人又会问有这个函数,我怎么没用过。那就说明:不是你刷题太少,就是atoi函数存在感太低。 这篇函数就带你领略atoi函数的魅力
|
C语言
C语言模拟实现:atoi函数
库函数atoi的使用方法以及它的模拟实现的思路。
130 0