几个常考的关于字符串的函数实现
来源:互联网 发布:做淘宝客怎么操作 编辑:程序博客网 时间:2024/04/30 13:31
一下实现包括strlen(), strcpy(), strncpy(), strcat(), strncat(), 等等
#include<iostream>using namespace std;int strlen1(const char *str){ int i = 0; while (str[i] != '\0') i++; return i;}//赋值表达式返回左操作数 char *strcop1(char *des, const char *source){ if (des == source) return des; else { while (*des++ = *source++){}; return des; } }char *strncop1(char *des, const char *source, int n){ if (des == source) return des; else { while ((n--) && (*source != '\0')) { *des++ = *source++; } *des = '\0'; return des; }}int strcomp1(const char *des, const char *sou){ assert(des != NULL && sou != NULL); while (*des == *sou && *des && *sou) { ++des; ++sou; } return *des - *sou;} char *strcat(char* &des, const char *source){ while (*des != '\0') { ++des; } while (*source != '\0') *des++ = *source++; *des = '\0'; return des;}int main(){ char *r= "HELLO world!"; int len = strlen1(r); cout << "length:" << len << endl; char *sour = "hello"; char arry[20]; //strcop1(arry, sour); strncop1(arry, sour, 5); puts(arry); char *p = strcat(arry, r); puts(p); cout << strcomp1(r, arry) << endl; system("pause"); return 0;}
0 0
- 几个常考的关于字符串的函数实现
- 关于字符串常考函数
- 几个常考字符串函数处理
- java常考的几个排序
- 几个面试常考的问题
- 面试常考的几个题
- 常考的 c/常考的 c函数/常考的 c++/常考的 c++函数/ja
- 关于字符串的几个函数
- 面试常考的atoi函数
- 几个字符串函数的实现
- 几个字符串函数的实现
- Java实现面试常考的算法
- 面试常考的数据结构Java实现
- CSS常考布局的实现方式
- C++几个常考的关键字的用法
- C++常考的上机题型:判断一个字符串是否为回文串(递归实现)
- 关于字符串的几个有用函数
- 关于几个字符串操作的函数
- 空间花开缓缓打开放松放松
- 基本数据结构-队列的实现及其运用
- lower_bound和upper_bound
- 分的非的非沃尔夫斯的非
- leetcode Add Two Numbers
- 几个常考的关于字符串的函数实现
- 总结一下这几天学的《JavaScript DOM编程艺术 第2版》(1)
- 型材生产线出席慈善大使
- 模板:KMP模板
- 改变字体的颜色和大小
- 【BJOI 2014】总结
- oc中属性以及属性的特性
- 为什么谷歌实习生月薪是5678美金?
- 【leetcode】ZigZag Conversion