atoi() 函数解析
来源:互联网 发布:淘宝链接生成器 编辑:程序博客网 时间:2024/06/15 21:18
头文件:#include <stdlib.h>
atoi() 函数用来将字符串转换成整数(int),其原型为:
int atoi (const char * str);
【函数说明】atoi() 函数会扫描参数 str 字符串,跳过前面的空白字符(例如空格,tab缩进等,可以通过 isspace() 函数来检测),直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
【返回值】返回转换后的整型数;如果 str 不能转换成 int 或者 str 为空字符串,那么将返回 0。
温馨提示:ANSI C 规范定义了 stof()、atoi()、atol()、strtod()、strtol()、strtoul() 共6个可以将字符串转换为数字的函数,大家可以对比学习。另外在 C99 / C++11 规范中又新增了5个函数,分别是 atoll()、strtof()、strtold()、strtoll()、strtoull(),在此不做介绍,请大家自行学习。
范例:将字符串a 与字符串b 转换成数字后相加。执行结果:
Enter a number: 233cyuyan
The value entered is 233.
atoi() 函数用来将字符串转换成整数(int),其原型为:
int atoi (const char * str);
【函数说明】atoi() 函数会扫描参数 str 字符串,跳过前面的空白字符(例如空格,tab缩进等,可以通过 isspace() 函数来检测),直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
【返回值】返回转换后的整型数;如果 str 不能转换成 int 或者 str 为空字符串,那么将返回 0。
温馨提示:ANSI C 规范定义了 stof()、atoi()、atol()、strtod()、strtol()、strtoul() 共6个可以将字符串转换为数字的函数,大家可以对比学习。另外在 C99 / C++11 规范中又新增了5个函数,分别是 atoll()、strtof()、strtold()、strtoll()、strtoull(),在此不做介绍,请大家自行学习。
范例:将字符串a 与字符串b 转换成数字后相加。
- #include <stdio.h>
- #include <stdlib.h>
- int main ()
- {
- int i;
- char buffer[256];
- printf ("Enter a number: ");
- fgets (buffer, 256, stdin);
- i = atoi (buffer);
- printf ("The value entered is %d.", i);
- system("pause");
- return 0;
- }
Enter a number: 233cyuyan
The value entered is 233.
0 0
- atoi() 函数解析
- atoi函数
- atoi函数
- atoi () 函数
- atoi函数
- atoi()函数
- atoi 函数
- atoi函数
- atoi函数
- atoi函数
- atoi函数
- atoi函数
- atoi函数
- atoi函数
- atoi()函数
- atoi函数
- atoi函数
- atoi()函数
- 第二章 怎样把android studio快捷键设置与eclipse一样
- 使用uiautomator的python封装进行android的UI测试
- opencv 图像减色
- Handler Looper MessageQueue
- 快学Scala第20章----Actor
- atoi() 函数解析
- c语言中关于n个元素的栈和c1赋不上值的问题
- IOS中UIScrollView的详细使用
- VC++ 高效、快速给REG_DWORD赋值
- Android RecyclerView Item动画(Checkbox全选、单选)
- jQuery限制 checkBox 选择个数
- 学习笔记----如何从零打造一个手游客户端
- 【poj3261】 Milk Patterns
- jQuery:unbind方法的使用详解