类型转换之字符串转int型
来源:互联网 发布:青岛企业网站seo技巧 编辑:程序博客网 时间:2024/05/22 05:01
函数原型:
int atoi(
int atoi(
const char *str );int _wtoi( const wchar_t *str );
包含头文件:#include <stdlib.h>
函数参数:str:要转换的字符串。
函数返回值:成功返回转换后的数值,失败返回0.超过最大值返回LONG_MAX,小于最小值返回LONG_MIN.
示例程序:
#include "stdafx.h"#include <stdlib.h>#include <errno.h>int _tmain(int argc, _TCHAR* argv[]){ char *str = NULL; wchar_t *wstr = NULL; int value = 0; // An example of the atoi function. str = " -3536 "; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function. str = "41412765"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); // Another example of the atoi function // with an overflow condition occuring. str = "5556402735171707160320"; value = atoi( str ); printf( "Function: atoi( \"%s\" ) = %d\n", str, value ); if (errno == ERANGE) { printf("Overflow condition occurred.\n"); } ////////////////////////////////////////// wstr = L" -36309 "; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); // Another example of the _wtoi function. wstr = L"124544667"; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); // Another example of the _wtoi function // with an overflow condition occuring. wstr = L"548556564171707160320"; value = _wtoi( wstr ); printf( "Function: _wtoi( \"%ws\" ) = %d\n", wstr, value ); if (errno == ERANGE) { printf("Overflow condition occurred.\n"); } getchar(); return 0;}运行结果:
另外,字符串转长整型介绍:http://blog.chinaunix.net/uid-29121609-id-4030955.html
字符串转换为double型:http://blog.chinaunix.net/uid-29121609-id-4031108.html
0
上一篇:类型转换之字符串转换为长整型
下一篇:类型转换之字符串转double型
相关热门文章
- 用Wrod功能实现任意纵横...
- 即依法治国
- 这就是法律规范法律关系实现权...
- Linux进程间通信——使用消息...
- web.py 学习 20140211
- test123
- 编写安全代码——小心有符号数...
- 使用openssl api进行加密解密...
- 一段自己打印自己的c程序...
- sql relay的c++接口
- 一个简单的shell脚本问题...
- 网站如何做图片的防盗链功能呢...
- 如何将printf输出的字符(含有...
- 嵌入式linux wifi移植 libert...
- Ø ⊆ {Ø} 是否是对的 ,这么...
给主人留下些什么吧!~~
评论热议
0 0
- 类型转换之字符串转int型
- 数值型字符串转换成int类型
- 类型转换之字符串转double型
- C风格字符串,int型,string类型相互转换
- 字符串类型转int类型
- 把字符串转换成int,float类型
- int short型类型转换
- 时间字符串转int类型
- SQL字符串转Int类型
- QT类型转换之整形转字符串
- jquery把int类型转换成字符串类型
- 有关int,float,double型与字符串char*类型的相互转换
- 最近听到一个面试题,将数值型字符串转换成int类型
- c++类型转换String^,int,string,char*,时间格式字符串
- SQL 将ID字符串转换为int 类型方便查找
- js把字符串转换成int类型的方法总结
- 把一个字符串转换成int类型(Java实现)
- 字符串下16进制转换成int类型
- 16道嵌入式C语言笔试面试题(经典!)
- 华为的一道机试题及答案(压缩字符串)
- Struts旅程(六)Struts页面转发控制ActionForward和ActionMapping
- 虚函数和纯虚函数的区别
- 类型转换之字符串转换为长整型
- 类型转换之字符串转int型
- 类型转换之字符串转double型
- CListctrl使用方法
- CListctrl基本用法
- 注册表API函数
- 自己使用Clistctrl的一些总结
- 硬盘基本知识
- 两个float值比较大小
- 冯诺依曼体系结构和哈佛体系结构
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
门锁锁芯价格
防盗门锁了怎么办
防盗门锁那种好
门锁更换
更换防盗门锁
防盗门如何更换锁芯
怎么更换锁芯
更换防盗门锁芯价格
锁芯如何更换
盼盼防盗门锁芯更换
高级防盗门锁芯
如何更换防盗门锁
怎么换雨刮器图解
雨刮器怎么换
换雨刮器图解
怎么换雨刷器
换雨刮器
怎么换雨刮器
汽车雨刮器怎么换图解
雨刮片多久换一次
雨刮多久换一次
怎么换雨刮片
雨刮水标志
米其林雨刮
雨刮条怎么换
雨刮水可以用自来水吗
雨刮水可以加洗洁精吗
雨刮刮不干净怎么办
颐达雨刮片尺寸
雨刮那个牌子好
荣威350雨刮片
雅绅特雨刮片尺寸
雨刮更换方法
雨刷怎么拆
无骨雨刷怎么拆
雨刮器怎么拆 图解
怎么拆雨刮器
雨刮器安装图解
换鞋跟多少钱
换鞋凳鞋柜尺寸
原木换鞋凳