首页 > 作文

详解C语言对字符串处理函数的实现方法

更新时间:2023-04-04 08:19:54 阅读: 评论:0

目录
strlen:1.计数器版本:2.递归的版本3.指针-指针版本st三年级综合实践教案rcat:strcmp:总结

strlen:

1.计数器版本:

#include<stdio.h>#include<string.h>#include<asrt.h>int my_strlen(const char *str)文明城市标语{int count =0;asrt(str!=null);while(*str!='
#include<stdio.h>#include<string.h>#include<asrt.h>int my_strlen(const char *str){int count =0;asrt(str!=null);while(*str!='\0'){count++;str++;}return count;} 
'){count++;str++;}return count; }

2.递归的版本

int my_strlen(const char *str){ asrt(str != null); if (*str == '
int my_strlen(const char *str){asrt(str != null);if (*str == '\0')return 0;return炎帝的故事 (my_strlen(++str)+1);}
') return 0; return (my_strlen(++str)+1);}

3.指针-指针版本

int my_strlen(const char *str){  char *end = str;  asrt(str!=null);  asrt(end!=null);  while (*end != '
int my_strlen(const char *str){char *en彬彬有礼的意思d = str;asrt(str!=null);asrt(end!=null);while (*end != '\0'){end++;}return end - str;}
') { end++; } return end - str;}

strcat:

#include<stdio.h>#include<string.h>#include<asrt.h>char *my_strcat(char *dest,char *str){char *ret=dest;//存dest的首地址 asrt(dest&&str);while(*dest){dest++;}while(*dest++=*str++);dest=ret;return dest;}

strcmp:

int my_strcmp(char *str1, char *str2){asrt(str1&&str2);while(*str1==*str2){if(str1=='
int my_strcmp(char *str1, char *str2){asrt(str1&&str2);while(*str1==*str2){if(str1=='\0'&&str2=='\0')return 0;str1++;str2++; }if(*str1>*str2)return 1;r端午节祝福eturn -1;//或return str1-str2;} 
'&&str2=='
int my_strcmp(char *str1, char *str2){asrt(str1&&str2);while(*str1==*str2){if(str1=='\0'&&str2=='\0')return 0;str1++;str2++; }if(*str1>*str2)return 1;return -1;//或return str1-str2;} 
')return 0;str1++;str2++; }if(*str1>*str2)return 1;return -1; //或return str1-str2; }

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注www.887551.com的更多内容!

本文发布于:2023-04-04 08:19:53,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/4d8ecd05df4b89046efd884623ef0c2b.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:详解C语言对字符串处理函数的实现方法.doc

本文 PDF 下载地址:详解C语言对字符串处理函数的实现方法.pdf

标签:版本   递归   指针   炎帝
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图