atoi 和itoa用法
1.itoa
在linux下没有itoa这个函数
原型:char *itoa(int value,char *string,int radix)
用法:#include <stdlib.h>
功能:将整数value转换成字符串存入string, radix为转换时所用基数(保存到字符串中的数据的进制基数 2 8 10 16)
说明:返回指向转换后的字符串的指针
举例:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
int number = 12345;
char string[25];
itoa(number, string,10);
printf("integer = %d string = %s\n", number, string);
return 0;
}
2.
atoi
字符串转换到整型数:
int atoi(const char *nptr)
跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
范例
/* 将字符串a 与字符串b转换成数字后相加*/
#include
mian()
{
char a[]=”-100”;
char b[]=”456”;
int c;
c=atoi(a)+atoi(b);
printf(c=%d\n”,c);
}
执行
c=356
在linux下没有itoa这个函数
linux下的字符转换函数只有:
atof 字符串转换到浮点型数
atoi 字符串转换到整型数: int atoi(const char *nptr);跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
atol 字符串转换到长整型数
ecvt 浮点型数转换到字符串,取四舍五入
fcvt 浮点型数转换到字符串,取四舍五入
gcvt 浮点型数转换到字符串,取四舍五入
strtod 字符串转换到浮点型数
strtol 字符串转换到长整型数
strtoul 字符串转换到无符号长整型数
toascii 将整形数转换合法的ASCII字符串
atoi 和itoa用法的更多相关文章
- 面试:atoi() 与 itoa()函数的内部实现(转)
原 面试:atoi() 与 itoa()函数的内部实现 2013年04月19日 12:05:56 王世晖 阅读数:918 #include <stdio.h> #include < ...
- atoi 和 itoa的实现
atoi 和 itoa是面试笔试经常要考到的题目,下面两份代码是用C语言实现的atoi和itoa: 1, atoi 原型: int atoi(const char *nptr); 函数说明: 参数np ...
- atoi 和 itoa
转自:http://www.cnblogs.com/cobbliu/archive/2012/08/25/2656176.html atoi 和 itoa是面试笔试经常要考到的题目,下面两份代码是用C ...
- atoi、itoa,strcpy,strcmp,memcpy等实现
原文:http://www.cnblogs.com/lpshou/archive/2012/06/05/2536799.html 1.memcpy.memmove.memset源码 link:http ...
- c常用函数-atoi 和 itoa
atoi 和 itoa atoi的功能是把一个字符串转为整数 Action(){ int j; char *s=""; j = atoi(s); lr_output_message ...
- 工作的准备:atoi,itoa,strcpy,memcpy,strcmp,二分查找,strcat
对常见的几个函数,周末没事写写,绝对是笔试面试中非频繁,前面n届学长无数次强调了,大家就别怀疑了.从今天开始,每天10道题. int atoi(const char* str) { if(str==N ...
- C函数的实现(strcpy,atoi,atof,itoa,reverse)
在笔试面试中经常会遇到让你实现C语言中的一些函数比如strcpy,atoi等 1. atoi 把字符串s转换成数字 int Atoi( char *s ) { int num = 0, i = 0; ...
- c语言实现atoi和itoa函数。
首先看atoi函数: C语言库函数名: atoi 功 能: 把字符串转换成整型数. 名字来源:ASCII to integer 的缩写. 原型: int atoi(const char *nptr); ...
- c++实现atoi()和itoa()函数(字符串和整数转化)
(0) c++类型所占的字节和表示范围 c 语言里 类型转换那些事儿(补码 反码) 应届生面试准备之道 最值得学习阅读的10个C语言开源项目代码 一:起因 (1)字符串类型转化为整数型(Integer ...
随机推荐
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
- php创建带logo的二维码
<?php /** php使用二维码 **/ class MyQrcode{ const SIZE = 150; const LEVEL = "L"; const MARGI ...
- Leetcode 238 Product of Array Except Self 时间O(n)和空间O(1)解法
1. 问题描写叙述 给定一个n个整数的数组(n>1n>1)nums,返回一个数组output,当中的元素outputioutput_i的值为原数组nums中除numsinums_i之外的全 ...
- 又一道软通动力7K月薪面试题——银行业务调度系统
后期补充:网友对我诟病最多的就是我帮学生做面试题,说这是小偷和骗子行为,在此,我对自己给学员做面试题做出例如以下解释: (1)学员拿着面试题来找老师,学生也事先思考和尝试后实在没有办法,又求职心切才 ...
- Chrome开发者工具详解(3):Timeline面板
Timeline面板 Timeline面板是整个面板里面最复杂的一个面板,涉及的东西比较多.可以利用这个面板来记录和分析网页运行过程中的所有活动行为信息. 你可以充分利用这个面板来分析你的网页的程序性 ...
- 自制获取data-自定义属性
jQuery.fn.dataset = function(attr, val) { // 获取数据集 if (arguments.length == 0) { var dataset = {}; jQ ...
- document.write 存在几个问题?应该注意
document.write (henceforth DW) does not work in XHTML XHTML 不支持 DW executed after the page has finis ...
- SQL Server根据列名查表
select a.name, b.name from syscolumns a, sysobjects b where a.name = 'XXXX' and a.id = b.id and b.xt ...
- iOS-OC-基础-NSString常用方法
NSString常用方法和属性 //compare 比较字符串升序.相同还是降序,比较原理:首先比较第一个字符(ASCII码比较),如果是升序就为升序,如果相同比较下一个字符... NSString ...