每日C(4.字符串转换篇)
字符串转换篇
atof
atoi
atol
gcvt
strtod
strtol
strtoul
toascii
tolower
toupper
atof(将字符串转换成浮点型数)
相关函数
atoi,atol,strtod,strtol,strtoul
表头文件
#include <stdlib.h>
定义函数
double atof(const char *nptr);
函数说明
atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。参数nptr字符串可包含正负号、小数点或E(e)来表示指数部分,如123.456或123e-2。
返回值
返回转换后的浮点型数。
附加说明
atof()与使用strtod(nptr,(char**)NULL)结果相同。
范例
/* 将字符串a 与字符串b转换成数字后相加*/
#include<stdlib.h>
main()
{
char *a=”-100.23”;
char *b=”200e-2”;
float c;
c=atof(a)+atof(b);
printf(“c=%.2f\n”,c);
}
执行
c=-98.23
atoi(将字符串转换成整型数)
相关函数
atof,atol,atrtod,strtol,strtoul
表头文件
#include<stdlib.h>
定义函数
int atoi(const char *nptr);
函数说明
atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
返回值
返回转换后的整型数。
附加说明
atoi()与使用strtol(nptr,(char**)NULL,10);结果相同。
范例
/* 将字符串a 与字符串b转换成数字后相加*/
#include<stdlib.h>
mian()
{
char a[]=”-100”;
char b[]=”456”;
int c;
c=atoi(a)+atoi(b);
printf(c=%d\n”,c);
}
执行
c=356
atol(将字符串转换成长整型数)
相关函数
atof,atoi,strtod,strtol,strtoul
表头文件
#include<stdlib.h>
定义函数
long atol(const char *nptr);
函数说明
atol()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
返回值
返回转换后的长整型数。
附加说明
atol()与使用strtol(nptr,(char**)NULL,10);结果相同。
范例
/*将字符串a与字符串b转换成数字后相加*/
#include<stdlib.h>
main()
{
char a[]=”1000000000”;
char b[]=” 234
相关文档:
The meaning of the c in calloc was vividly discussed in comp.lang.c in October 2000 (see here), with both clear (because, unlike malloc, calloc clears the memory it returns) and count (because, unlike malloc, calloc is passed a count of elements to allocate) suggested as possible explanations, howev ......
目的:当程序在前台运行时,按挂机键程序不退出,只是退到后台运行,程序在后台运行时,按c键能把程序结束
方法:在HandleWsEventL()中屏蔽挂机键KAknUidValueEndKeyCloseEvent,在值在avkon.hrh中定义,实践中发现8.0sdk的avkon.hrh没有定义KAknUidValueEndKeyCloseEvent,唯有手工添加定义#define KAknUidValueEndK ......
众所周知,strcmp为字串比较只用,简单的函数并不简单。
下面的代码
int main()
{
char* cp1 = {'z', 'h', 'a', 'n', 'g'};
char* cp2 = {'z', 'h', 'a', 'n', 'g'};
std::cout<<strcmp(cp1, cp2)<< ......