字符串类型转换成整数类型

字符串类型转换成整数(atoi, _atoi64)、浮点类型,长整形(atol).

#include<stdlib.h>

原型:double atof(const char* string);

函数介绍:将字符串转换成浮点型

eg:

         float f;

        char* str = "1234.33";

        f = atof(str);

        printf("string = %s float = %f", str, f);

原型:int atoi(const char* string);

函数介绍:将字符串转换成整形数

eg:

               int n;

              char* str = "1234.34";

              n = atoi(str);

              printf("string = %s  interger = %d\n", str, n);

结果:

原型:long atol(const char* string);

eg:

#include <stdlib.h>

#include <stdio.h>

void main( void )

{

   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 */  

  l = atol( s );  

  printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值