什么是atoi() [英] what is atoi( )

查看:91
本文介绍了什么是atoi()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你能解释一下wat atoi()函数是为了什么例子

如何使用它?

Hi
could you please explain wat atoi( ) function is for and an example
how to use it?

推荐答案



sudharsan写道:

sudharsan wrote:
您好
请您解释wat atoi()函数是为了和一个例子
如何使用它?
Hi
could you please explain wat atoi( ) function is for and an example
how to use it?




只要拿起任何关于C的书或者做一个男人atoi来帮助你。它将

文本转换为整数值。


例如atoi(234)将返回234作为int,你可以

随后进行算术运算。


我们也有itoa()和其他类似函数。


char str [] = 234;


int iVal;


iVal = atoi(str);


它基本上从每个字符中减去0以获得数字。



Just pick up any book on C or do a man atoi to help you. It converts a
text to integer value.

for example atoi("234") would return you 234 as int on which you can
subsequently do arithmetic operations.

We also have itoa() and other similar functions.

char str[]= "234";

int iVal;

iVal = atoi(str);

It basically subtracts ''0'' from each character to get you the numeric.


>你能解释一下wat atoi()函数是为了一个例子吗
> could you please explain wat atoi( ) function is for and an example
如何使用它?




atoi函数尝试转换一个字符串为整数。对于

实例:


#include< stdlib.h>


int main(void){

int a;


a = atoi(" 1234");

返回0;

} b / b
在这个例子中,atoi将转换字符串1234。到整数

数字1234.这是另一个例子:


#include< stdlib.h>


int main(void){

int a = atoi(" 223asdf");

返回0;

}


这将转换为223。到了223.字符串的其余部分不是考虑到
。如果字符串无法转换为数字,那么atoi

将返回零。



The atoi function tries to convert an string to a integer number. For
instance:

#include <stdlib.h>

int main (void) {
int a;

a = atoi ("1234");
return 0;
}

In this example, atoi will convert the string "1234" to the integer
number 1234. This is another example:

#include <stdlib.h>

int main (void) {
int a = atoi ("223asdf");
return 0;
}

This will convert "223" to 223. The remainder of the string is not
considered. If the string cannot be converted to a number, at all, atoi
returns zero.




sudharsan写道:

sudharsan wrote:
你好
请你解释一下wat atoi()函数是为了一个例子
如何使用它?
Hi
could you please explain wat atoi( ) function is for and an example
how to use it?




你最好找一本涵盖标准

库的好C书。


这里的摘录来自C标准(7.20.1.2p1-3):


#include< stdlib.h>

int atoi(con​​st char * nptr);

long int atol(const char * nptr);

long long int atoll(const char * nptr);


atoi,atol和atoll函数分别将nptr指向的
字符串的初始部分转换为int,long int和long long int

表示。除了出错的行为,他们

相当于< strtol()>的调用示例。


atoi,atol和环礁函数返回转换后的值。


示例(我的,不是标准版):


/ *我没有测试过这个* /

#include< stdlib.h>


int main(无效)

{

return atoi(" 42");

}



You''re much better of finding a good C book that covers the standard
library.

Here''s excerpt from the C Standard (7.20.1.2p1-3):

#include <stdlib.h>
int atoi(const char *nptr);
long int atol(const char *nptr);
long long int atoll(const char *nptr);

The atoi, atol, and atoll functions convert the initial portion of the
string pointed to by nptr to int, long int, and long long int
representation, respectively. Except for the behavior on error, they
are equivalent to <examples of calls to strtol()>.

The atoi, atol, and atoll functions return the converted value.

Example (mine, not from Standard):

/* I haven''t tested this */
#include <stdlib.h>

int main(void)
{
return atoi("42");
}


这篇关于什么是atoi()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆