当前位置: 代码迷 >> C语言 >> [求助]有人可一说说atoi函数吗?
  详细解决方案

[求助]有人可一说说atoi函数吗?

热度:257   发布时间:2007-04-12 20:32:27.0
[求助]有人可一说说atoi函数吗?
???????????
搜索更多相关的解决方案: atoi  函数  

----------------解决方案--------------------------------------------------------
谢谢qq0001000
----------------解决方案--------------------------------------------------------
再问问s[i]=='-'表示什么意识啊?
----------------解决方案--------------------------------------------------------
如果数组s中第i个元素是减号,
----------------解决方案--------------------------------------------------------
不太懂啊!!有哪位大虾帮忙教一下我E-mail yangfan.6523815@163.com 在此谢过
----------------解决方案--------------------------------------------------------
函数名: atoi
功 能: 把字符串转换成长整型数
用 法: int atoi(const char *nptr);
程序例:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}

自己好好看看吧 呵呵
----------------解决方案--------------------------------------------------------
回复
相关函数  atof,atol,atrtod,strtol,strtoul
表头文件 #include<stdlib.h>
定义函数 int atoi(const char *nptr);
函数说明 atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到 非数字或字符串结束时('\0')才结束转换,并将结果返回。
返回值 返回转换后的整型数。
附加说明 atoi()与使用strtol(nptr,(char**)NULL,10);结果相同。
范例 /* 将字符串a 与字符串b转换成数字后相加*/
#include<stdlib.h>
mian()
{
char a[]=”-100”;
char b[]=”456”;
int c;
c=atoi(a)+atoi(b);
printf(c=%d\n”,c);
}
执行
c=356

[此贴子已经被作者于2007-4-13 17:00:03编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案