atoi() 函数用来将字符串转换成整数(int)
来源:互联网 发布:网络上刘皇叔是什么梗 编辑:程序博客网 时间:2024/04/30 03:29
头文件:#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() 函数用来将字符串转换成整数(int)
- C语言atoi()函数:将字符串转换成int(整数)
- C语言atoi()函数:将字符串转换成int(整数)
- C语言atoi()函数:将字符串转换成int(整数)
- C语言atoi()函数:将字符串转换成int(整数)
- atoi()函数:将字符串转换成int
- C语言atoi()函数:将字符串转换成int(整数)和sprintf和memset
- 将字符串转换成整数 atoi
- //实现一个atoi的函数,atoi是将字符串转换成整数
- 字符串转换成整数函数实现(atoi)
- 关于atoi字符串转换成int整数的一些问题
- c语言:模拟实现库函数的atoi函数,将字符串转换成整数
- atoi函数:c\c++中把字符串整数转换为int型整数
- atoi(char *str)将字符串转换成整数
- atoi(char *str)将字符串转换成整数
- 字符串转换成整数(atoi)函数的具体实现
- atoi函数,字符串转换为整数
- atoi(将字符串转换成整型数)和itoa(把一整数转换为字符串)
- vue.js开发环境搭建
- 工厂模式Factory
- Activity的生命周期
- 运算符重载典例:Vector-维克多
- OpenResty 环境搭建
- atoi() 函数用来将字符串转换成整数(int)
- 欢迎使用CSDN-markdown编辑器
- 抽象工厂模式Abstract Factory
- eWorld.ASP.Maker.v2017.0.3.x86.Incl.Keygen-DARKSiDERS
- java BpDeep
- Web服务器点击劫持(ClickJacking)的安全防范
- 微信小程序与H5的区别
- 腾讯云Centos7安装Apache +MySQL+PHP +JDK +Tomcat
- 关于OAuth2.0认证的理解和java实现