整數(shù)轉(zhuǎn)換為字符串:char *itoa( int value, char *string,int radix);
小數(shù)轉(zhuǎn)換為字符串:sprintf(串, 格式控制符列, 數(shù)據(jù));
字符串轉(zhuǎn)小數(shù):double atof(const char *nptr);
字符串轉(zhuǎn)整數(shù):int atoi(const char *nptr);
測試代碼:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a=2013420;
float b=2.054f;
double c=5.24;
char sa[20],sb[20],sc[20];
//將整數(shù)a轉(zhuǎn)換為字符串
itoa(a,sa,10);
puts(sa);
//將浮點型數(shù)據(jù)轉(zhuǎn)換為字符串
sprintf(sb,"%g",b);
puts(sb);
//將double型數(shù)據(jù)轉(zhuǎn)換為字符串
sprintf(sc,"%lg",c);
puts(sc);
printf("========以下是串轉(zhuǎn)換為數(shù)值=========/n");
char *s1="123",*s2="1.23";
printf("%d/n",atoi(s1));
printf("%g/n",atof(s2));
getchar();
return 0;
}