一文搞懂:_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
相关文章
|
9月前
|
C语言
【C语言】atoi函数的使用和模拟实现
本篇将介绍atoi函数的使用,通过实例讲解函数的使用方法,模拟实现atoi函数。
89 1
|
8月前
|
C语言
【c语言】atoi的模拟实现
【c语言】atoi的模拟实现
38 0
|
4天前
|
算法 C语言
【C语言】:atoi函数的使用及其模拟实现
【C语言】:atoi函数的使用及其模拟实现
11 5
|
23天前
|
C语言
C语言学习记录——模拟字符串相关函数(strcpy、strlen、strcat)相关知识-const、typedef
C语言学习记录——模拟字符串相关函数(strcpy、strlen、strcat)相关知识-const、typedef
13 1
|
8月前
|
C语言
了解C语言中的atoi函数和模拟实现
了解C语言中的atoi函数和模拟实现
|
8月前
|
Go
Go语言strconv不会? 字符串转换直看这里
Go语言strconv不会? 字符串转换直看这里
27 0
|
10月前
|
编译器 C语言
【C语言进阶】字符函数及字符串函数,带你掌握核心用法并模拟实现(1)——strlen,strcpy,strcmp
【C语言进阶】字符函数及字符串函数,带你掌握核心用法并模拟实现(1)——strlen,strcpy,strcmp
107 1
|
9月前
|
API C语言
利用strstr与atoi的结合实现一个C语言获取文件中数据的工具
利用strstr与atoi的结合实现一个C语言获取文件中数据的工具
39 0
|
11月前
itoa随手记(itoa是什么,itoa怎么用)
itoa随手记(itoa是什么,itoa怎么用)
114 0
|
C语言
C语言模拟实现:atoi函数
库函数atoi的使用方法以及它的模拟实现的思路。
109 0