请问如何将字符串变量转换成整型和浮点型变量,多谢各位高手指点

解决方案 »

  1.   

    将字符串转换成双精度(atof)、整数(atoi,atoi64)或者长整数(atol)。
    double atof(const char *string);
    int ati(const char *string);int64 
    atoi64(const char *string);
    long atol(const char *string);
      

  2.   

    char *s; 
    double x; 
    int i; 
    long l;
    s = " -2309.12E-15"; /* Test of atof */
    x = atof( s );
    printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
    s = "7.8912654773d210";/* Test of atof */
    x = atof( s );
    printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );
    s = " -9885 pigs";/* Test of atoi */i = atoi( s );
    printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );
    s = "98854 dollars";/* Test of atol */i = atol( s );
    printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
      

  3.   

    atoi()
    atof()
    strtol()
    strtoul()
      

  4.   

    atoi   atof  atol