央视塔旋转餐厅多少钱:c语言中atof 和atoi是什么意思?

来源:百度文库 编辑:中科新闻网 时间:2024/05/04 19:34:38

  1. 这两个都是C语言的库函数

  2. 函数名: atoi 
    功 能: 把字符串转换成长整型数 
    用 法: #include <stdlib.h> 
    int atoi(const char *nptr); 
    程序例: 
    #include <stdlib.h> 
    #include <stdio.h> 

    int main(void) 

    int n; 
    char *str = "1234"; 

    n = atoi(str); 
    printf("string = %s integer = %d\n", str, n); 
    return 0; 


    运行结果是:
    string =1234 integer=1234

  3. 函数名: atof 
    功 能: 把字符串转换成浮点数 
    用 法: double atof(const char *nptr); 
    程序例: 
    #include <stdlib.h> 
    #include <stdio.h> 

    int main(void) 

    float f; 
    char *str = "12345.67"; 

    f = atof(str); 
    printf("string = %s float = %f\n", str, f); 
    return 0; 
    }

分别是字符串转换成浮点型数和字符串转换成整形数。