(C)string的一些常用函数原型
来源:互联网 发布:linux ssh远程登录 编辑:程序博客网 时间:2024/05/13 13:24
1.int strlen(const char *s)
2.char * strdup(const char *s)
3.char* strcpy(char *tag,char *src)
4.char* strcat(char *str1,char *str2)
5.int strcmp(const char *str1,const char *str2)
一些实现方法(仅供参考):
1.
int mystrlen(const char *str)
{
if(NULL==str)
throw "Invalid argument(s)";
int len=0;
while(*str++!='\0')
{
len++;
}
return len;
}
2.
char* mystrdup(const char *str)
{
if(NULL==str)
throw "Invalid argument(s)";
char *p=NULL;
char *tag=NULL;
char *n=NULL;
const char *src=str;
int len=0;
len=mystrlen(n);
p=(char*)malloc(sizeof(char*)*len+1);
tag=p;
while(*str)
{
*p++=*str++;
}
*p='\0';
return tag;
}
3.
char* mystrcpy(char* tag,const char* src)
{
if((NULL==tag)||(NULL==src))
throw "Invalid argument(s)";
const char *s=src;
char *t=tag;
while(*s!='\0')
{
*t++=*s++;
}
*t='\0';
return tag;
}
4.
char* mystrcat(char *str1,const char *str2)
{
if((NULL==str1)||(NULL==str2))
throw "Invalid argument(s)";
char *s1=str1;
const char *s2=str2;
while(*s1) s1++;
while(*s2!='\0')
{
*s1++=*s2++;
}
*s1='\0';
return str1;
}
5.
int mystrcmp(const char *str1,const char *str2)
{
if((NULL==str1)||(NULL==str2))
throw "Invalid argument(s)";
while(*str1==*str2)
{
str1++;
str2++;
if(*str1=='\0'&&*str2=='\0')
return 0;
}
if(*str1>*str2)
return 1;
else
return -1;
}
- (C)string的一些常用函数原型
- C++string 类常用函数的函数原型
- string常用函数原型
- string.h中一些函数的原型
- C++string常用的函数
- c str常用函数原型
- string类的一些常用成员函数
- string常用的一些函数总结
- string的一些常用函数用法
- string库函数-----------总结一些常用的处理string的函数
- C语言的一些string函数
- C#----String的常用成员函数
- C++string类的常用函数
- string一些常用函数基础
- 一些不安全的常用的C函数
- 几个常用的函数原型
- 一些常用的C语言函数源代码
- c语言中一些常用的函数
- Linux/Unix关机、重启(shutdown\reboot\halt\init)等命令
- JAVA-------反射机制
- C++ Regex 邮箱校验
- 第二十天(C++代码重用V)
- 针对Python 右键没有Edit with IDLE的解决方法
- (C)string的一些常用函数原型
- vim 按文本行长度进行排序
- INT 字段 原数相加或是相减
- MSSQL优化之索引优化
- 用gallery实现可滑动的Tab
- c++中消息函数(2)----GetMessage函数
- C#实现UDP打洞
- 关于uboot.lds文件的分析
- java----泛型