# 实现常用字符串函数的功能

/*****************************************************
copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd.
Authorer  ChenYangYang     erey_Jobs    Version:0.1    Date: 2016/11/14
Description 自己实现字符串的比较函数
Funcion List:
*****************************************************/

#include <stdio.h>

#define MAX_SIZE 1024

int my_strcmp(char *dest, char *src)
{

char *temp = dest;
while(*src != '\0')
{
if(*temp > *src)
{
return 1;
}
else if(*temp < *src)
{
return -1;
}
temp++;
src++;
}

if(*src == '\0' && *temp == '\0')
{
return 0;
}

if(*src == '\0' && *temp != '\0')
{
return 1;
}

if(*temp == '\0' && *src != '\0')
{
return  -1;
}
}

int main()
{
char src[MAX_SIZE] = "hello world a";
char dest[MAX_SIZE] = "hello world ";

int result = my_strcmp(dest,src);

printf("result = %d\n",result);

return 0;
}


/*****************************************************
copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd.
Authorer ChenYangYang     erey_Jobs    Version:0.1    Date:2016/11/14
Description 字符串连接函数
Funcion List:
*****************************************************/

#include <stdio.h>

#define MAX_SIZE 1024

char *my_strcat(char *dest, char *src)
{
char *temp = dest;
while( *temp != '\0')
{
*temp++;
}
while(*src != '\0')
{
*temp = *src;
*temp++;
*src++;
}
*temp = '\0';
return dest;
}

int main()
{
char src[MAX_SIZE] = "hi  where are yo doing";
char dest[MAX_SIZE] = "how are you";

char *temp = my_strcat(dest,src);

printf("temp = %s\n",temp);
printf("dest = %s\n",dest);

return 0;
}


/*****************************************************
copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd.
Authorer ChenYangYang erey_Jobs    Version:0.1    Date:2016/11/14
Description 自己实现字符串长度函数
Funcion List:
*****************************************************/

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 1024

int my_strlen(char * src)
{
int len = 0;
while( * src != '\0')
{
*src++;
len++;
}
return len;
}

int main()
{
char src[MAX_SIZE] = "hello world";
int len;
len = my_strlen(src);

printf("the len = %d\n",len);

return 0;
}


/*****************************************************
copyright (C), 2016-2017, Lighting Studio. Co.,     Ltd.
Authorer ChenYangYang    Version:0.1    Date:2016/11/14
Description 自己实现字符串拷贝函数
Funcion List:
*****************************************************/

#include <stdio.h>
#include <string.h>
#define MAX_SIZE
char *my_strcpy(char *dest, char *src)
{
char *temp = dest;
while(*src != '\0')
{
*temp = *src;
*temp++;
*src++;
}
*temp = '\0';
return dest;
}

int main()
{
char src[MAX_SIZE] = "welcome to china";
char dest[MAX_SIZE] = "hello world";

char *temp = my_strcpy(dest,src);

printf("temp = %s\n",temp);
printf("dest = %s\n",dest);

return 0;
}


#### C/C++中常用的字符串处理函数和内存字符串函数

2015-07-09 16:02:28

#### 常见字符串函数的实现

2017-12-24 20:52:35

#### 总结的php10个常用的处理字符串的函数事例

2013-08-27 17:34:59

#### PLSQL 字符串函数、数学函数、日期函数

2012-12-10 17:40:24

#### C++常用的字符串处理函数-全

2016-05-09 15:26:01

#### 函数与字符串函数

2018-02-23 18:56:27

#### 数据库SQl语言最常用的字符串函数

2015-11-27 23:27:03

#### php常用函数之-字符串函数

2016-05-18 11:56:06

#### Python中必须掌握的常用字符串处理函数

2017-12-08 21:35:34

#### PHP常用字符串函数小结

2015-01-16 11:31:21