为什么ATOI在此代码中返回0?

Lee*_*ton 0 c atoi

我刚开始使用C而且我正在尝试学习ATOL功能.有人能告诉我它为什么一直打印0?我知道这意味着转换无法执行,但我不确定原因.

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int i = atoi ("  bl149");
    printf("%d\n", i);  
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

fac*_*487 5

atoi基本上将具有数字的字符串转换为整数1,并且将转换的任何字符串将成为它的返回值.或者更精确的atoi函数从字符串的开头开始检查.如果它有数字(仅从开始),那么它将以整数形式返回该值.下面的例子将清除概念例如

atoi("1234") 
--> it will convert string "1234" in to integer and return it 
         --> i.e. ouput is 1234
atoi("1234abcd") --> i.e. ouput is 1234
atoi("a1234abcd") --> i.e. ouput is 0   
Run Code Online (Sandbox Code Playgroud)

在你的情况下,因为你的字符串从b("b1149")开始,所以它将返回0