atoi atof atol

在c语言中提供了把字符串转化为整数的函数,并没有提供把整数转化为字符串的函数

atoi是标准的库函数

itoa不是标准的库函数(在vs可编译,其它系统中未知)

atol把一个字符串转化为long类型

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h> 
 4 
 5 int main()
 6 {
 7     char a[100] = "123";
 8     char b[100] = "400";
 9     int i = 0;
10     
11     i = atoi(a) + atoi(b);   //atoi功能是把字符串转化为整数int,需要加头文件<stdlib.h>
12     printf("%d\n", i);
13     
14     char c[100] = "3.5";
15     double f = atof(c);      //atof把一个小数形式的字符串转化为一个浮点数 
16     printf("%lf\n", f); 
17     
18     int num = 26;
19     sprintf(a, "%d", num);   //sprintf实现把数字num转化为字符串放入a中 
20     printf("%s\n", a);
21     char d[100] = "abc";
22     strcat(d, a);        //连接字符串,放入d中 
23     printf("%s", d);
24     
25     return 0; 
26 }

 

posted @ 2018-01-28 14:34  heheheda  阅读(171)  评论(0编辑  收藏  举报