strlen
#include <stdio.h>
#include <string.h>
int MY_STRLEN(char *p)
{
int count = 0;
while(*p != '\0'){
count++;
p++;
}
return count;
}
int main()
{
char arr[100] = {'\0'};
gets(arr);
int len = MY_STRLEN(arr);
printf("%d\n",len);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7d2b9af4a11d7f8aa8457e614ab13fe3.png)
strcpy
#include <stdio.h>
#include <string.h>
char MY_STRCPY(char *dest,const char *src)
{
while(*src != '\0')
{
*dest = *src;
dest++;
src++;
}
*dest = '\0';
}
int main()
{
char arr1[100] = {'\0'};
char arr2[100] = {'\0'};
gets(arr1);
gets(arr2);
MY_STRCPY(arr2,arr1);
printf("%s\n",arr2);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3ae5de07396e30ca67e9489ee73ff63c.png)
strcat
在#include <stdio.h>
#include <string.h>
char MY_STRCAT(char *dest,const char *src)
{
int i = 0;
while(*dest != '\0')
{
*dest = *dest;
dest++;
}
while(*src != '\0')
{
*dest = *src;
dest++;
src++;
}
}
int main()
{
char arr1[100] = {'\0'};
char arr2[100] = {'\0'};
gets(arr1);
gets(arr2);
MY_STRCAT(arr2,arr1);
printf("%s\n",arr2);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0a59032e07193d15743616889c9d1387.png)
strcmp
#include <stdio.h>
#include <string.h>
int MY_STRCMP(char *p,char *q)
{
while(*p == *q )
{
if(*p == '\0'){
return 0;
}else{
p++;
q++;
}
}
return *p - *q;
}
int main()
{
char arr1[100] = {'\0'};
char arr2[100] = {'\0'};
int ret;
printf("正数代表第一个字符串大于第二个字符串,0代表等于,负数代表小于\n");
gets(arr1);
gets(arr2);
ret = MY_STRCMP(arr1,arr2);
printf("%d\n",ret);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7792ce81a1017feea0ede7ed44668672.png)