标签:rcm const ret using main class 操作 char col
#include<iostream> #include<stdlib.h> #include<string> #include <assert.h> using namespace std; //连接字符串 被copy的要用const char *my_strcat(char *d, const char *t) { char *address = d; while (*d != ‘\0‘) //将原字符串指针移到最后一个字符 d++; while ((*d++ = *t++) != ‘\0‘) //开始复制 NULL; return address; //返回指针 } //字符串的复制 同样被复制的为了安全 要用const char *my_strcpy(char *d,const char *t) { char *str = d; while (*t != ‘\0‘) { *d = *t; *d++,*t++; } //复制到结束为 \0 return str; } //从第n个字符开始复制 char *my_strncpy(char *dest, char *t, int n) { char *str = dest; //用指针str来操作 while (n&&*t != ‘\0‘) { *dest = *t; ++*dest, ++*t; n--; } return str; } //小写转大写 char *my_strup(char *dest) { char *str = dest; while (*dest != ‘\0‘) { //判断是否输的确实是小写 if (*dest >= ‘a‘ && *dest <= ‘z‘) *dest -= 32; dest++; } return str; } //大写转小写 char *my_strlwr(char *dest) { char *str = dest; while (*dest != ‘\0‘) { //判断是否输的为大写 if (*dest >= ‘A‘ && *dest <= ‘Z‘) *dest += 32; dest++; } return str; } //比较字符比较大小 被比较的字符串都要用使用const int my_strcmp(const char *s1, const char * s2) { while (*s1&&*s2&&*s1 == *s2) { s1++; s2++; } return (*s1 - *s2); //如果相等 返回0 大于 返回正 小于 返回负 } int main() { char a[100],b[100]; cin >>a>> b; char *p1 = a, *p2 = b; //连接字符串 //cin >> a >> b; //my_strcat(p1, p2); //把b复制到a //my_strcpy(p1, p2); //从第n开始复制 //my_strncpy(p1, p2, 2); //cin >> b; //cout << my_strcmp(p1, p2); //小写转大写 大写转小写 //cin >> a; //my_strup(p1); //cout << a<<endl; //my_strlwr(p1); //cout << a << endl; cout<<my_strcmp(a, b)<<endl; system("pause"); return 0; }
标签:rcm const ret using main class 操作 char col
原文地址:https://www.cnblogs.com/Stephen-Jixing/p/9866705.html