
C/C++库函数模拟
Aroula
C/C++后端程序开发的一名程序猿
展开
-
常见库函数模拟实现及注意事项
1.常见字符串管理库函数1)strlen,这个函数的方法有很多种实现方式,分别如下size_t my_strlen4(const char *str){ assert(str != NULL); //一般参数若为const型指针时不需要对参数检测,但思想得有 if (*str == '\0') return 0; else //此处若为my_strlen4(str++)+1,就陷入死循环了 return my_strlen4(str + 1) + 1;//此处若为my_strlen原创 2021-05-03 17:44:59 · 250 阅读 · 2 评论 -
模拟实现strcmp函数
#pragma warning(disable:4996) #include <stdio.h>#include <string.h>#include <assert.h>int my_strcmp(const char *a, const char *b){ assert(a != NULL&&b != NULL); const char *tmpd = a; const char *tmps = b; int ret = 0; w.原创 2021-04-17 23:44:24 · 301 阅读 · 3 评论 -
模拟实现strcpy函数
//模拟实现strcpy#include <stdio.h>#include <string.h>#include <assert.h>char* my_strcpy(char *a, const char *b){ assert(a != NULL&&b != NULL);//检测参数的有效性 char *tmpd = a; //保护参数 const char *tmps = b; while (*tmps !原创 2021-04-17 22:00:11 · 194 阅读 · 1 评论