字符串类函数的实现
来源:互联网 发布:php 权限管理 数据 编辑:程序博客网 时间:2024/06/05 14:33
char *strcpy(char *strDest ,const char * strSrc )
{
if(strDest == NULL || strSrc == NULL)
return 0;
char *address = strSrc;
while((*strDest++ = *strSrc++) != '\0')
NULL;
return addressl;
}
//字符串比较函数,相等返回0,s1大返回正整数,s2大返回负整数
int mystrcmp(const char *s1,const char *s2)
{
while(*s1!='/0'&&*s2!='/0'&&(*s1==*s2)) s1++,s2++;
return (*s1)-(*s2);
}
//字符串长度函数,长度不包括结尾的'/0'
int mystrlen(const char *s)
{
int res = 0;
while(*s++!='/0')
res++;
return res;
}
//字符串连接函数
char *mystrcat(char *source,const char *dest)
{
if(source ==NULL || dest == NULL)
return 0;
char *s = source;
while(*s!='/0')s++;
while(*dest!='/0')*s++ = *dest++;
*s='/0';
return source;
}
//字符串转换小写字母函数
char *mystrlwr(char *source)
{
char *s = source;
do
{
if(*s>='A'&&*s<='Z')
*s+=32;
} while (*s++!='/0');
return source;
}
//字符串转换大写字母函数
char *mystrupr(char *source)
{
char *s = source;
do
{
if(*s>='a'&&*s<='z')
*s-=32;
} while (*s++!='/0');
return source;
}
/字符串倒转函数
char *mystrrev(char *source)
{
char *s1 = source,*s2 = source,temp;
while(*s2!='/0')s2++;
if(s1!=s2)s2--;//找中值,交换分界点
while(s1<s2)temp = *s1,*s1 = *s2,*s2 = temp,s1++,s2--;
return source;
}
//字符串查找指定字符串的第一次出现,没有出现返回NULL,出现则返回出现的位置
static const char* _strstr(const char* s1, const char* s2)
{
assert(s2 && s1);
const char* p=s1, *r=s2;
while(*p!="\0”)
{
while(*p++==*r++);
if(*r=="\0”)
return p;
else
{
r=s2;
p=++s1;
}
}
return NULL;
}
- //strSrc指向的字符串循环右移n个字符后保存到strDest中并返回
- char * circulate_right_move(char *strDest,const char *strSrc,const int n)
- {
- assert( (strDest != NULL) && (strSrc != NULL));
-
- char * address = strDest;
- int len = strlen(strSrc);
- int offset = n % len;
-
- strSrc += (len - offset);
-
- for(;(*strDest = *strSrc) != '\0';strDest++,strSrc++);
-
- strSrc -= len;
-
- for(int i = 0; i < len - offset; i++)
- {
- *strDest = *strSrc;
- strDest++;
- strSrc++;
- }
-
- *strDest = '\0';
- return address;
- }
- 字符串类函数的实现
- 字符串函数的实现
- 字符串函数的实现
- 字符串函数的实现
- 字符串函数的实现
- 字符串函数的实现
- c++类实现字符串的基本函数
- 关于字符串函数的实现
- 字符串处理函数的实现
- 字符串处理函数的实现
- 字符串函数的自我实现
- 字符串连接函数的实现
- 字符串相关函数的实现
- 字符串处理函数的实现
- 字符串部分函数的实现
- 字符串操作函数的实现
- 实现自己的字符串函数
- 几个字符串函数的实现
- Struts2_三种传参数方法
- java 可中断线程
- 项目4(自己扩充)输出流的自定义
- Hibernate @OneToMany的mappedBy和@JoinColumn总结
- mac上搭建openfire服务器
- 字符串类函数的实现
- Tim Sweeney解释为什么Unreal Engine 4全面转向C++
- 多线程复制文件
- JDK、Eclipse、Myeclipse、Tomcat及插件下载、安装及配置方法
- Flex代码格式化工具 Flexformatter插件 安装与使用
- TabHost的使用(一)
- 安卓学习之路_20140417
- 经典排序算法
- 多线程