atoi()函数

    原型: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

 

 

相关文章:

  • 2022-12-23
  • 2021-06-29
  • 2022-02-27
  • 2022-12-23
  • 2021-08-24
  • 2021-12-30
  • 2021-08-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-25
  • 2021-12-24
  • 2021-09-19
  • 2021-10-18
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案