当前位置:网站首页>Atof(), atoi(), atol() functions [detailed]
Atof(), atoi(), atol() functions [detailed]
2022-07-25 05:28:00 【Holy cat】

Introduction to this issue
This paper mainly introduces :atof()、atoi()、atol() How functions are used , What are the functions , And some noteworthy points in use .
List of articles
One 、 Preface
C Language provides some library functions that can convert numeric strings into numbers , for example atof()、atoi()、atol() function . The functions of these functions are introduced below :
- atof() function : Converts a string to double Type data .
- atoi() function : Converts a string to int Type data .
- atol() function : Replace the string with long int Type data .
Be careful : If the input cannot be converted to this type of data , The return value is 0.
Two 、atof() function
double atof( const char *string );
stay VS In the compiler atof() The library function needs to reference two header files before calling <stdlib.h> and <math.h>.atof() The function needs to pass a string as a parameter , And the string needs to have a certain format :
1. Scientific form of counting :
[ Space ][+/-][ Numbers ][. Numbers ][ {d |D |e |E }[+/-] Numbers ]
2. Decimal form :[ Space ][+/-][ Numbers ][. Numbers ]
atof() The parameter string is scanned , Skip the preceding space character , It's not until you meet a number or a sign that you start to convert , Then judge strictly according to the format requirements , Until the format is illegal or the end of string flag is encountered ‘\0’ Will end the conversion , Return to one double Data of type . Take a few examples :
3、 ... and 、atoi()、atol() function
int atoi( const char *string );
long atol( const char *string );
stay VS In the compiler atoi() and atol() Function needs to reference a header file <stdlib.h>. There is no difference between these two functions in the parameter transfer part , There are only differences in the return value of the function :atoi() Back to a int Type data ,atol() Back to a long int Type data .
The string of parameters also has a certain format :[ Space ][+/-][ Numbers ]. and atoi()、atol() The function will scan the parameter string first , Skip the preceding space character , It's not until you meet a number or a sign that you start to convert , Then until you encounter non numeric characters or string end flags ‘\0’ Will end the conversion , Returns a number . Take a few examples :
Be careful : If atof() function 、atio() function 、atol() Overflow occurs when the return value of a function is greater than the maximum value of its return type , As a result, some part of the returned data is lost .
边栏推荐
- ZTE's first 5g mobile phone, axon 10 pro, was launched in the first half of this year
- rhcsa暑假第二天
- 剑指offer专项突击版第9天
- odoo14 | 关于状态栏statusbar关键词使用后显示异常及解决方法
- VPP不能加载UP状态接口
- 深圳随到随考,科目四随到随考,科三理论第二理论随到随考说明
- Build keyword driven automated testing framework
- 微服务 - 配置中心 - Nacos
- Unity接入ChartAndGraph图表插件
- [cloud co creation] design Huawei cloud storage architecture with the youngest cloud service hcie (Part 1)
猜你喜欢

JWT(json web token)

Redis cluster setup (Windows)

STL notes (IV): String

Performance Optimization: how to solve the slow loading speed of the first screen of spa single page application?

Panda3D keyboard moving scene

STL notes (III): input / output stream

Redis集群搭建(Windows)

微信小程序相关操作示例

The difference between function and task in SystemVerilog

systemverilog中function和task区别
随机推荐
Execution process of NPM run XX
Introduction to base ring tree
Implement is by yourself_ base_ of
编程大杂烩(二)
Microservice - hystrix fuse
Pikachu vulnerability platform exercise
systemVerilog中automatic用法
微服务 - Hystrix 熔断器
Win11 how to view the file explorer tab
基环树入门
Which website is suitable for physical server
DOM processing in ahooks
Interface idempotency
js 页面增加过渡层
What should testers do if they encounter a bug that is difficult to reproduce?
VPP不能加载UP状态接口
Sword finger offer special shock edition day 9
"Niuke | daily question" inverse Polish expression
JWT(json web token)
Delivery practice of private PAAS platform based on cloud native