原型:int  atoi (const  char  *nptr)

    用法:#include  <stdlib.h>

    功能:将字符串转换成整型数;atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负号才开始做转换,而再遇到非数字或字符串时('\0')才结束转化,并将结果返回。

    说明:atoi()函数返回转换后的整型数。

    举例:

#include <stdio.h>  
#include <stdlib.h>  
  
int main()  
{  
    char a[] = "-100";  
    char b[] = "456";  
    int c = 0;  
      
    c = atoi(a) + atoi(b);  
      
    printf("c = %d\n",c);  
}

 

结果:c = 356

posted on 2016-12-08 10:01  Stephanie7464  阅读(167)  评论(0编辑  收藏  举报