C函数的实现(strcpy,atoi,atof,itoa,reverse)
来源:互联网 发布:淘宝网的地位和特点 编辑:程序博客网 时间:2024/05/17 08:51
在笔试面试中经常会遇到让你实现C语言中的一些函数比如strcpy,atoi等
1. atoi
把字符串s转换成数字
int Atoi( char *s ){int num = 0, i = 0;int sign = 1;for( i=0; isspace(s[i]); i++ );sign = (s[i] == '-')? -1:1;if( s[i] == '+' || s[i] == '-' )i++;for( ;isdigit(s[i]); i++ ){num = 10*num + (s[i]-'0');}return sign*num;}
2. strcpy(char *src, char *dst)
把src复制到dst中
int Strcpy(char* src, char *dst){//register char *tmp;int i = 0;while( src[i]!= NULL ){dst[i] = src[i++];}}
3.itoa( int n, char *s )
把数字转化成字符串
void Reverse( char *s ){int size = 0;char tmp;while( s[size] != NULL )size++;size--;int i=0;while( i <= size>>1 ){tmp = s[i], s[i] = s[size-i], s[size-i] = tmp;i++;}}void ItoA( int n, char *s ){int sign = 1;if( n < 0 ){sign = -1;n = -n;}int i=0; do{s[i++] = n%10 + '0';}while((n/=10) > 0);if( sign == -1 )s[i++] = '-';s[i] = '\0';Reverse( s );}
4. atof( char * s )
把字符串转化成double类型
double AtoF( char *s ){int sign = 1;int i = 0;for( i=0; isspace(s[i]); i++ );sign = (s[i] == '-')? -1:1;if( s[i] == '+' || s[i] == '-' )i++;double num = 0.0;double pow = 1.0;//整数 for( ;isdigit(s[i]); i++ )num = num*10 + (s[i]-'0');for( i++; isdigit(s[i]); i++ ){num = num*10 + (s[i]-'0');pow *= 10;}return sign * (num/pow);}
- C函数的实现(strcpy,atoi,atof,itoa,reverse)
- C/C++ atoi、atof与itoa函数的实现
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)
- C语言实现atoi,itoa和atof
- memcpy, strcpy, strlen, strcmp, itoa, atoi 的函数实现
- C函数atoi,itoa的实现代码
- 基础函数的实现(strcpy,strcat, strcmp, atoi, itoa)【转】
- atoi,itoa,strcpy,strcp,memcpy的实现
- 常用的函数:atoi,itoa,atof,_ttoi等
- 常用的函数:atoi,itoa,atof,_ttoi等
- 常用的函数:atoi,itoa,atof,_ttoi等
- itoa与atoi ftoa与atof的实现
- C语言实现atoi和atof函数
- 编程实现C函数 atoi atof
- atoi、atof、itoa、itow函数简介
- atof(),atoi(),itoa(),sprintf()函数详解
- Android Layout XML属性
- 描述在浏览器中敲入一个网址并按下回车后所发生的事情
- Spfa模板
- Struts2中变量值接收和使用
- 1005:I Think I Need a Houseboat
- C函数的实现(strcpy,atoi,atof,itoa,reverse)
- 进程和线程区别总结
- Using RMAN duplicate Created Remote Auxiliary Database
- Java中的static关键字
- recv_peek偷窥函数和UNIX域间文件描述符传递sendmsg、recvmsg
- Darwin流媒体服务器源码分析
- PDF文件解密
- PBOC/EMV之静态数据认证(SDA)与动态数据认证(DDA)
- 这个今天知道