//memcpy函数的使用和模拟
//只考虑大小,不考虑内容
//#include<stdio.h>
//#include<string.h>
//int main()
//{
// int arr1[10] = { 0,1,2,3,4,5,6,7,8,9 };
// int arr2[10] = { 0 };
// /*memcpy(arr2, arr1, 5 * sizeof(int));*///以字节为单位
// memcpy(arr2, arr1 + 3, 5 * sizeof(int));//从3开始拷贝5个字符
// for (int i = 0; i < 10; i++)
// {
// printf("%d\n", arr2[i]);
// }
// return 0;
//}
//#include<stdio.h>
//#include<string.h>
//void* my_memcpy(void* dest, const void* src, size_t num)
//{
// void* ret = dest;
// while (num--)
// {
// *(char*)dest = *(char*)src;//强制类型转化是临时的效果
// dest=*(char*)dest+1;
// src=*(char*)src+1;
// }
// return ret;
//}
//void* my_memmove(void* dest, const void* src, size_t num)
//{
// void* ret = dest;
// if (dest < src)
// {
// while (num--)
// {
// *(char*)dest = *(char*)src;
// dest=*(char*)dest+1;
// src=*(char*)src+1;
// }
// }
// else
// {
// while (num--)
// {
// *((char*)dest+num)=*((char*)src + num);
// }
// }
// return ret;
//}
//int main()
//{
// int arr1[10] = { 0,1,2,3,4,5,6,7,8,9 };
// int arr2[10] = { 0 };
// /*memcpy(arr2, arr1, 5 * sizeof(int));*///以字节为单位
// my_memcpy(arr2, arr1 + 3, 5 * sizeof(int));//从3开始拷贝5个字符
// my_memcpy(arr1+2, arr1 , 5 * sizeof(int));重叠的用memmove来处理 不重叠的用memcpy
// memmove(arr1+2, arr1 , 5 * sizeof(int));
// /*my_memmove(arr1 + 2, arr1, 5 * sizeof(int));*/
// for (int i = 0; i < 10; i++)
// {
// printf("%d\n", arr1[i]);
// }
// return 0;
//}
//memset函数--内存设置
//#include<stdio.h>
//int main()
//{
// char arr[10] = "hello,bit";
// int arr1[10] = {1,2,3,4,5,6,7,8,9,10};
// //memset(arr1, 1, 40 );//0x01010101
// memset(arr, 'x', 5);//以字节为单位来设置的
// printf("%s\n", arr);//xxxxx,bit
// return 0;
//}
//memcmp函数
//#include<stdio.h>
//int main()
//{
// int arr1[] = { 1,2,3,4,5,6,7,8,9,10 };
// int arr2[] = { 1,2,3,4,3 };
// int ret = memcmp(arr1, arr2, 20);//第一个小返回-1//要是超过范围了就返回-1
// printf("%d\n", ret);
// return 0;
//}
//字符串函数
//strlen的使用和模拟实现
//#include<stdio.h>
//#include<string.h>
//int main()
//{
// char arr[] = "abcdef";
// size_t len = strlen(arr);
// printf("%zd\n", len);
// return 0;
//}
//#include <stdio.h>
//#include <string.h>
//int main()
//{
// const char* str1 = "abcdef";
// const char* str2 = "bbb";
// //strlen返回的是无符号整形 3-6=3
// if (strlen(str2) - strlen(str1) > 0)//(int)strlen(str2)可以强转成整形
// {
// printf("str2>str1\n");
// }
// else
// {
// printf("srt1>str2\n");
// }
// return 0;
//}
//#include<stdio.h>
//#include<assert.h>
//size_t my_strlen(const char* str)
//{
// size_t count = 0;//size_t strat=str;
// assert(str);
// while (*str)
// {
// count++;
// str++;
// }
// return count;//str-strat;
//}
//int main()
//{
// char arr[] = "abcdef";
// size_t len = my_strlen(arr);
// printf("%zd\n", len);
// return 0;
//}
//#include<stdio.h>
//#include<assert.h>
//size_t my_strlen(const char* str)
//{
// assert(str);
// if (*str == '\0')
// return 0;
// else
// return 1 + my_strlen(str + 1);
//}
//int main()
//{
// char arr[] = "abcdef";
// size_t len = my_strlen(arr);
// printf("%zd\n", len);
// return 0;
//}
//strcpy的使用和模拟实现
//#include<stdio.h>
//#include<string.h>
//int main()
//{
// char arr1[20] = "xxxxxxxxxxxxxxxxxxx";
// char arr2[] = "hello";
// char arr3[] = { 'a','b','c' };
// strcpy(arr1, arr3);//拷贝字符串 会把原字符(包括\0)拷贝到要拷贝的地方
// printf("%s\n", arr1);//原字符串必须含有\0 并且拷贝的字符大小不应该超过数组大小,否则会崩溃
// return 0;
//}
//
//#include<stdio.h>
//#include<assert.h>
//char* my_strcpy(char* dest, char* src)
//{
// char* ret = dest;
// assert(dest);
// assert(src);
// //while (*src != '\0')
// //{
// // //*dest = *src;
// // //dest++;
// // //src++;
// // *dest++ = *src++;
// //}
// //*dest = *src;
// while (*dest++ = *src++)
// {
// ;
// }
// return ret;
//}
//int main()
//{
// char arr1[20] = {0};
// char arr2[] = "abcdef";
// printf("%s", my_strcpy(arr1, arr2));
// return 0;
//}
//NULL-->0 一般用于指针初始化
//'\0'-->字符串结束标记
//0-->数字0
//'0'--字符,本质是48
//null或NUL-->\0
//strcat 函数的模拟实现
//1.找到目标字符的\0
//2.拷贝字符串到目标空间\0之后
//注意:1.目标字符串必须有\0
//2.空间必须足够大
//3.目标空间可以更改
//4.原字符串有\0
//#include<stdio.h>
//#include<string.h>
//int main()
//{
// char arr1[20] = "abcdef";
// char arr2[] = "hello";
// strcat(arr1, arr2);
// printf("%s\n", arr1);
// return 0;
//}
//#include<stdio.h>
//#include<assert.h>
//char* my_strcat(char* arr1,char* arr2)
//{
// assert(arr1 && arr2);
// char* ret = arr1;
// while (*arr1)
// {
// arr1++;
// }
// while (*arr1++ = *arr2++)
// {
// ;
// }
// *arr1 = *arr2;
// return ret;
//}
//int main()
//{
// char arr1[20] = "abcdef";
// char arr2[] = "hello";
// printf("%s\n",my_strcat(arr1, arr2) );
// //printf("%s\n", my_strcat(arr1, arr1));不安全//会死循环
// return 0;
//}
//strcmp函数的使用和模拟
//对应位置字符串的大小 小的字符串小于大的字符串
//前面的小,返回<0的数
//#include<stdio.h>
//#include<string.h>
//int main()
//{
// int ret = strcmp("bbq", "abcdef");
// if (ret > 0)
// {
// printf("大于");
// }
// else if(ret==0)
// {
// printf("等于");
// }
// else
// {
// printf("小于");
// }
// return 0;
//}
//
//
//#include<stdio.h>
//#include<string.h>
//int my_strcmp(const char* s1, const char* s2)
//{
// while (*s1 == *s2)
// {
// if (*s1 == '\0')
// {
// return 1;
// }
// s1++;
// s2++;
// }
// if (*s1 > *s2)
// {
// return 1;
// }
// else
// {
// return -1;
// }
//}
//int main()
//{
// int ret =my_strcmp("bbq", "abcdef");
// if (ret > 0)
// {
// printf("大于");
// }
// else if (ret == 0)
// {
// printf("等于");
// }
// else
// {
// printf("小于");
// }
// return 0;
//}
//%d int
//%hd short
// %ld long
// %lld long long
//%zu/%zd size_t
//
//strcpy等不安全
//strncpy
//strncat
//strncmp
//#include<stdio.h>
//int main()
//{
// char arr1[20] = "xxxxxxx";
// char arr2[] = "hello";
// strncpy(arr1, arr2, 3);
// printf("%s\n", arr1);//不拷贝\0
// strncpy(arr1, arr2, 7);
// printf("%s\n", arr1);//如果原字符串不够就补\0
// return 0;
//}
//#include<stdio.h>
//int main()
//{
// char arr1[20] = "hello\0xxxxxxxxx";
// char arr2[] = "world";
// strncat(arr1, arr2, 4);
// printf("%s\n", arr1);//补n个字符后在其后面加\0
// strncat(arr1, arr2, 8);//只会追加全部后加\0
// printf("%s\n", arr1);
// return 0;
//}
//#include<stdio.h>
//int main()
//{
// char arr1[20] = "wolld";
// char arr2[] = "world";
// int ret = strncmp(arr1, arr2, 2);
// printf("%d\n", ret);//只比较n个
// return 0;
//}
//strstr函数的模拟和实现
//在一个字符串找另一个字符串,有则返回第一个的位置,无则返回NULL
//#include<stdio.h>
//int main()
//{
// char arr1[] = "abcdef";
// char arr2[] = "deq";
// char* ret = strstr(arr1, arr2);
// printf("%s\n", ret);
// return 0;
//}
//#include<stdio.h>
//#include<assert.h>
//char* my_strstr(const char* str1, const char* str2)
//{
// const char* cur = str1;
// const char* s1=NULL;
// const char* s2=NULL;
// assert(str1 && str2);
// if (*str2 == '\0')
// {
// return (char*)str1;
// }
// while (*cur)
// {
// s1 = cur;
// s2 = str2;
// while (*s1 && *s2 && s1 == s2)
// {
// s1++;
// s2++;
// }
// if (*s2 == '\0')
// {
// return (char*)cur;
// }
// cur++;
// }
// return NULL;
//}
//int main()
//{
// char arr1[] = "abcdef";
// char arr2[] = "deq";
// char* ret = my_strstr(arr1, arr2);
// if (ret == NULL)
// {
// printf("找不到");
// }
// else
// {
// printf("%s\n", ret);
// }
// return 0;
//}
//
//
//
//strtok函数的使用
//#include<string.h>
//#include<stdio.h>
//int main()
//{
// char arr[] = "zhangsan@1623.com#hehe";
// char arr2[30] = { 0 };//会将@和.改为\0
// strcpy(arr2, arr);
// const char* p = "@#.";
// char* s = NULL;
// for (s = strtok(arr2, p); s != NULL;s=strtok(NULL,p))
// {
// printf("%s\n", s);
// }
// return 0;
//}
//strerror函数
//对应错误码打印成错误信息
//#include<string.h>
//#include<stdio.h>
//int main()
//{
// for (int i = 0; i < 10; i++)
// {
// printf("%d=%s\n",i, strerror(i));
// }
// return 0;
//}