c库函数之一 - atoi函数

    xiaoxiao2021-12-04  78

    atoi()函数:

    1.功能:

    把字符串转换成整型数。

    2.原型:

    int atoi(const char *nptr);

    说明: 参数nptr字符串,如果第一个非空格字符 不存在或者不是数字也不是正负号则返回零否则开始做类型转换,之后检测到非数字(包括结束符 \0,小数点之类的) 字符时停止转换,返回整型数。

    3.头文件:<stdlib.h>

    4.实例:

    源码:

    1. #include <stdlib.h> 2. #include <stdio.h> 3. int main(void) 4. { 5. int num; 6. char *str = "-12345.67"; 7. num = atoi(str); 8. printf("string = %s integer =%d\n", str, num); 9. return 0; 10. }

    结果:

    转载请注明原文地址: https://ju.6miu.com/read-680238.html

    最新回复(0)