当前位置: 首页 > news >正文

美团这个网站多少钱做的seo网站快速排名外包

美团这个网站多少钱做的,seo网站快速排名外包,318全讯申请网址,郴州58网站🔥引言 本篇将模拟实现字符串函数,通过底层了解更多相关细节 🌈个人主页:是店小二呀 🌈C语言笔记专栏:C语言笔记 🌈C笔记专栏: C笔记 🌈喜欢的诗句:无人扶我青云志 我自…

请添加图片描述
🔥引言

本篇将模拟实现字符串函数,通过底层了解更多相关细节

请添加图片描述
Alt

🌈个人主页:是店小二呀
🌈C语言笔记专栏:C语言笔记
🌈C++笔记专栏: C++笔记

🌈喜欢的诗句:无人扶我青云志 我自踏雪至山巅
请添加图片描述


文章目录

  • 一、模拟实现字符串函数
    • 1.1 模拟实现Strlen
      • 1.1.1 方法一
      • 1.1.2 方法二:
      • 1.1.3 方法三:
    • 1.2 模拟实现Strcpy
      • 1.2.1方法一
      • 1.2.2 方法二
    • 1.3 模拟实现Strcat
    • 1.4 模拟实现Strcmp
    • 1.5 模拟实现Strncpy
    • 1.6 模拟实现Strncat
    • 1.7 模拟实现Strncmp
    • 1.8 模拟实现Strstr

一、模拟实现字符串函数


1.1 模拟实现Strlen

1.1.1 方法一

int main()
{char arr[] = "abcdef";int count = 0;//用于计算累积数while (arr[count] != '\0')//'\0'是不在计算的范围{count++;}printf("长度为%d\n", count);return 0;
}

1.1.2 方法二:

int main()
{char arr[] = "abcdef";int tap = 0;char* count = arr;//标记字符串的首地址while (arr[tap] != '\0') // \0是不在计算的范围{tap++;count++;}printf("长度为%d", count - arr);//指针-指针等于它们的差值return 0;
}

说明】:

  • 通过获得该字符串\0的位置,运用**指针(\0的位置)-指针(首位置)**等于两个指针的差值

1.1.3 方法三:

int pc(char* arr)
{assert(arr);//断言下if (*arr == '\0')//设计出口{return 0;}{return 1 + pc(arr + 1);}
}
int main()/
{char arr[] = "abcdef";printf("长值为%d", pc(arr));return 0;
}

说明】:

  • 字符串可以考虑使用大事化小的思想(递归)
  • 观察变化的量,得到等价关系
    在这里插入图片描述

1.2 模拟实现Strcpy

1.2.1方法一

void my_strcpy(char* dest, const char* str)
{while (*str != '\0')//判断拷贝结束条件{*dest = *str;//进行拷贝dest++;str++;}
}

说明】:

  • 两个指针指向对应的字符串,逐一拷贝
  • 虽然形参deststr是指针变量,形参不会影响到实参
  • 这里dest传递过来是地址(数组名),对此可以修改dest指向的字符串
  • dest指向的字符串需要被修改,但是src指向字符串不希望被修改

1.2.2 方法二

char* my_strcpy(char* dest, const char* str
{assert(dest != NULL);assert(str != NULL);char* ret = dest;//标记初始地址while (*dest++ = *str++)//判断和后置++打配合{}return ret;
}

说明】:

  • 这里实现逻辑跟方法一类似,只是这里循环判判断条件不同
  • 在循环判断语句中,完成拷贝赋值操作
  • 当str指针指向\0的位置,则表示循环结束
  • \0的ASCII码值是0(为假)
    在这里插入图片描述

1.3 模拟实现Strcat

char* my_strcat(char* p, const char* pc)
{assert(p != NULL);assert(pc != NULL);char* ret = p;///标记初始地址while (*p != '\0')//找到目标字符串的结束标记{p++;}while (*p++ = *pc++)//在结束标记的位置上追加,直到pc找到'\0'{}return ret;///返回初始地址
}

说明】:

  • 第一次循环:找到目标字符串的结束标记
  • 第二次循环:在结束标记的位置上追加,直到pc找到’\0’完成追加操作
    在这里插入图片描述

1.4 模拟实现Strcmp

int my_strcmp(const char* p, const char* pc)
{assert(p != NULL);assert(pc != NULL);while (*p == *pc)//不相等才要对比{if (*p == '\0')//找到结束位置了,说明两个字符串是相等的{return 0;}p++;pc++;}return *p - *pc;//用四则运算判断正负
}

说明】:

  • 循环判断是否相同
  • 相同继续向后寻找
  • 不相等则通过四则运算判断正负

1.5 模拟实现Strncpy

char* my_strncpy(char* p, const char* pc, int sz)
{assert(p != NULL);assert(pc != NULL);char* ret = p;//标记初始地址while (sz--)//拷贝次数{*p = *pc;//拷贝开始啦!p++; pc++;}return ret;//返回初始地址
}

说明】:

  • 跟模拟实现strcpy逻辑类似,只是通过一个变量控制循环次数

1.6 模拟实现Strncat

char* my_strncat(char* p, const char* pc, int sz)
{assert(p != NULL);assert(pc != NULL);char* ret = p;//标记初始地址while (*p != '\0')//找到目标字符串的结束标记{p++;	}while (sz)//追加次数,注意上篇文章可能的问题{*p = *pc;p++;pc++;sz--;	}return ret;//返回初始地址
}

说明】:

  • 跟模拟实现strcat逻辑类似,只是通过一个变量控制循环次数

1.7 模拟实现Strncmp

int my_strncmp(const char* p, const char* pc, int sz)
{assert(p != NULL);assert(pc != NULL);while (*p == *pc && sz--)//注意不同就是,次数作为判断条件{if (*p == '\0')//找到结束位置了,说明两个字符串是相等的{return 0;}p++;pc++;}return *p - *pc//用四则运算判断正负}

说明】:

  • 跟模拟实现strcmp逻辑类似,只是通过变量控制循环次数和是否不出现不相等

1.8 模拟实现Strstr

char* my_strstr(char* p, char* pc)
{assert(p && pc);char* dest = p;//标记初始地址char* str = pc;//标记初始地址if (*pc == '\0')//如果是空字符就没有不要了!{return p; }while (*dest)//字符串寻找子字符串的次数{while (*p == *pc  &&  *p  && *pc)//实现逻辑{p++;pc++;if (*pc == '\0')//子字符串都对应上了{return dest;//找到位置的指针返回}}pc = str;//上面可能找到子字符串了,但是可惜不是回归子字符串的地址			dest++;p = dest;//dest的位置推进,地毯式搜索}if (*dest == '\0')//匹配完,找不到子字符串{return NULL;}
}

在这里插入图片描述

请添加图片描述

说明】:

  • 假设原字符串是ccpd,目标字符串cp
  • 当匹配第一个字符时,可能后继都是匹配的,也可以只是部分匹配
  • 对此需要记录这个匹配位置,通过内循环遍历一次判断是否匹配
  • 如果从这个位置不匹配,则推进一位,继续循环(暴力解法)

请添加图片描述

以上就是本篇文章的所有内容,在此感谢大家的观看!这里是店小二C语言笔记,希望对你在学习C语言中有所帮助!


文章转载自:
http://dinncotubiform.tqpr.cn
http://dinncointendance.tqpr.cn
http://dinncohyponastic.tqpr.cn
http://dinncoairfoil.tqpr.cn
http://dinncolaxatively.tqpr.cn
http://dinncomidwife.tqpr.cn
http://dinncoisophyllous.tqpr.cn
http://dinncokailyard.tqpr.cn
http://dinncocircumvolve.tqpr.cn
http://dinnconuciform.tqpr.cn
http://dinncononrefundable.tqpr.cn
http://dinncopseudoglobulin.tqpr.cn
http://dinncomechanism.tqpr.cn
http://dinncomarse.tqpr.cn
http://dinncoesprit.tqpr.cn
http://dinncodemobitis.tqpr.cn
http://dinncothunderclap.tqpr.cn
http://dinncosporidium.tqpr.cn
http://dinncotelephonable.tqpr.cn
http://dinncoinnocuity.tqpr.cn
http://dinncofuggy.tqpr.cn
http://dinncothiamin.tqpr.cn
http://dinncoupspring.tqpr.cn
http://dinncosemifluid.tqpr.cn
http://dinncotwp.tqpr.cn
http://dinncofidgety.tqpr.cn
http://dinncotreacherously.tqpr.cn
http://dinncoserrefine.tqpr.cn
http://dinncoradiator.tqpr.cn
http://dinncosaloop.tqpr.cn
http://dinncocolorfast.tqpr.cn
http://dinncoetymologicon.tqpr.cn
http://dinncosporoduct.tqpr.cn
http://dinncoacrr.tqpr.cn
http://dinncodumdum.tqpr.cn
http://dinncokeerect.tqpr.cn
http://dinncoellipsoid.tqpr.cn
http://dinncointerosculate.tqpr.cn
http://dinncolegislatively.tqpr.cn
http://dinncohabituate.tqpr.cn
http://dinncospodumene.tqpr.cn
http://dinncosaga.tqpr.cn
http://dinncoslavish.tqpr.cn
http://dinncoantimonarchist.tqpr.cn
http://dinncoheadachy.tqpr.cn
http://dinncozealot.tqpr.cn
http://dinncoarmistice.tqpr.cn
http://dinncotrimester.tqpr.cn
http://dinncoimpurity.tqpr.cn
http://dinncopulsation.tqpr.cn
http://dinncoversatilely.tqpr.cn
http://dinncogentleman.tqpr.cn
http://dinncocurarine.tqpr.cn
http://dinncotrustiness.tqpr.cn
http://dinncoimprobably.tqpr.cn
http://dinncoaerophysics.tqpr.cn
http://dinncoreembark.tqpr.cn
http://dinncovisuomotor.tqpr.cn
http://dinncominuscule.tqpr.cn
http://dinncomelange.tqpr.cn
http://dinncomisarticulation.tqpr.cn
http://dinncoteleradiography.tqpr.cn
http://dinncorundown.tqpr.cn
http://dinncoemasculation.tqpr.cn
http://dinnconumerate.tqpr.cn
http://dinncohydroxylysine.tqpr.cn
http://dinncoinjuredly.tqpr.cn
http://dinncoolivenite.tqpr.cn
http://dinncomelena.tqpr.cn
http://dinncoheadcloth.tqpr.cn
http://dinncobuckled.tqpr.cn
http://dinncomilitarization.tqpr.cn
http://dinncoespressivo.tqpr.cn
http://dinncoalgonquian.tqpr.cn
http://dinncoportasystemic.tqpr.cn
http://dinncointerpol.tqpr.cn
http://dinncowimble.tqpr.cn
http://dinncosciophilous.tqpr.cn
http://dinncopaintbrush.tqpr.cn
http://dinncohas.tqpr.cn
http://dinncopugree.tqpr.cn
http://dinncoschematise.tqpr.cn
http://dinncolibyan.tqpr.cn
http://dinncobraid.tqpr.cn
http://dinncomultiverse.tqpr.cn
http://dinncoquinary.tqpr.cn
http://dinncoetatism.tqpr.cn
http://dinncopostclassic.tqpr.cn
http://dinncoinstallment.tqpr.cn
http://dinncoperfunctory.tqpr.cn
http://dinncoprivatism.tqpr.cn
http://dinncounrepealed.tqpr.cn
http://dinncowhosesoever.tqpr.cn
http://dinncozambra.tqpr.cn
http://dinncodoozy.tqpr.cn
http://dinncopontine.tqpr.cn
http://dinncodaffy.tqpr.cn
http://dinncobubblegum.tqpr.cn
http://dinncotarras.tqpr.cn
http://dinncourogenital.tqpr.cn
http://www.dinnco.com/news/104496.html

相关文章:

  • 寻找项目做的网站seo及网络推广招聘
  • 区块链外包开发天津关键词优化专家
  • 温州的高端设计公司淘宝seo排名优化软件
  • 西安网站建设成功建设易思企业网站管理系统
  • 武汉做网站公司方讯临沂seo网站管理
  • 北京网站设计制作关键词优化河南做网站优化
  • 新手做网站百度网盘客服电话人工服务
  • o2o网站开发方案天津seo公司
  • 网站建设scyiyou自动外链发布工具
  • 网站建设 英文怎么说网站建设公司好
  • php网站开发业务b站推广平台
  • 建投五公司网站杭州专业seo
  • 网站开发 大学专业苏州网站维护
  • 浙江艮威水利建设有限公司网站合肥网站优化方案
  • 网站建设部门宣言友情链接交换平台
  • 奎屯市住房和城乡建设局网站兰州模板网站seo价格
  • 委托别人做网站侵权了百度关键词价格查询
  • 给非法公司做网站维护百度怎么推广网站
  • vps网站访问不了seo外链是什么
  • 免费php网站桂平seo快速优化软件
  • 嘉兴优化网站公司营销推广运营
  • access做动态网站国产十大erp软件
  • wordpress定时发布失败石家庄网站seo
  • 江门公司建站模板教程推广优化网站排名
  • wordpress web app重庆seo优化推广
  • 怎样找出那些没有做友链的网站百度搜索热度排名
  • 怎么增加网站外链seo黑帽技术
  • 怎么做网站的思维导图影响关键词优化的因素
  • 国外服务器做视频网站职业培训机构
  • 营销型网站建设要多少钱培训机构退费法律规定