2010年9月5日星期日

atoi函数

toi函数原型: 
int atoi(char *str) 
函数用途: 
将字符串转换成一个整数值 
输入参数: 
str 待转换为整型数的字符串 
返回值: 
成功返回转换后的数值,失败则返回0


程序例:
#include <stdlib.h>
#include <stdio.h>
函数名: atof  
功 能: 把字符串转换成浮点数  
用 法: double atof(const char *nptr);  
程序例:  
#include  
#include  
 
int main(void)  
{  
float f;  
char *str = "12345.67";  
 
f = atof(str);  
printf("string = %s float = %f 
", str, f);  
return 0;  
}  
 
 
 
函数名: atoi  
功 能: 把字符串转换成整型数  
用 法: int atoi(const char *nptr);  
程序例:  
#include  
#include  
 
int main(void)  
{  
int n;  
char *str = "12345.67";  
 
n = atoi(str);  
printf("string = %s integer = %d 
", str, n);  
return 0;  
}  
 
 
 
函数名: atol  
功 能: 把字符串转换成长整型数  
用 法: long atol(const char *nptr);  
程序例:  
 
#include  
#include  
 
int main(void)  
{  
long l;  
char *str = "98765432";  
 
l = atol(lstr);  
printf("string = %s integer = %ld 
", str, l);  
return(0);  
}

没有评论:

发表评论