字符串

作者: Isy | 来源:发表于2016-07-30 02:28 被阅读7次

int main(int argc, const char * argv[]) {
    int ch;
    while((ch = getchar()) != EOF) {
        putchar(ch);
    }
    printf("EOF\n");
    return 0;
}
char a[][10] = {};
表示a[0] --> char [10]

char *a[] 
a[0] --> char *

$ln -s a.out my

$busybox

size_t strlen(const char *s);

size_t mylen(const char *s) {
    int cnt = 0;
    while(s[idx] != '\0') {
        idx++;
    }
    return idx;
}

int strcmp(const char *s1, const char *s2);

int mycmp(const char *s1, const char *s2) {
    for(int i = 0; i < strlen(s1); i++) {
        for (int j = 0; j < strlen(s2); j++) {
            if (s1[i] == s2[j]) {
                continue;
            }
            if (s1[i] > s2[j]) {
                return 1;
            }
            if (s1[i] < s2[j]) {
                return -1;
            }
        }
    }
    return 0;
}

int mycmp2(const char *s1, const char *s2) {
    //int idx = 0;
    //while(s1[idx] == s2[idx] && s1[idx] != '\0') {
    //  idx++;
    //}
    while (*s1 == *s2 && *s1 != '\0') {
        s1++; s2++;
    } 
    return *s1 - *s2;
    //return s1[idx] - s2[idx];
}


char *strcpy(char *restrict dst, const char *restrict src);
//restrict 表示dst和src不能重叠
//把src的内容拷贝到ds

char *dst = (char*)malloc(strlen(src)+1);
strcpy(dst,src);
char *mycpy(char * restrict dst, const char * restrict src) {
    int idx = 0;
//  while(src[idx] != '\0') {
//      dst[idx] = src[idx];
//      idx++;
//  }
//  dst[idx] = '\0';
    return dst;
    char *rest = dst;
    while(*dst++ = *src++) {
        NULL;
    }
    *dst = '\0';
    return rest;

} 
查找字符
char *strchr(const char *s, int c); // 左找
char *strrchr(const char *s, int c); // 右找
查找字符串
char *strstr(const char *s1, const char *s2);
char *strcasestr(const char *s1, const char *s2); //忽略大小写



相关文章

  • Javascript知识点整合

    字符串 单行字符串: ‘字符串’或“字符串” 多行字符串: `多行字符串` 字符串操作: 字符串连接‘+’号 长度...

  • C++基础字符串

    字符串的构造 字符串特性描述 字符操作 字符串赋值 字符串连接 字符串比较 字符串查找 字符串替换 字符串删除 字...

  • iOS中的NSString与NSMutableString

    字符串的创建 字符串读写 字符串的比较 字符串的搜索 字符串截取 字符串替换 字符串与路径 字符串转换 NSMut...

  • iOS NSString用法总结

    字符串属性 字符串截取 字符串比较 字符串搜索 字符串拼接 字符串基本类型转换 字符串分行,分段 字符串列举(按条...

  • php 字符串常见方法汇总

    字符串拼接 字符串检索 字符串截取 字符串替换 字符串大小写转化 字符串转数组 字符串格式化

  • iOS 字符串截取、iOS 字符串替换、iOS 字符串分隔、iO

    iOS之字符串截取、iOS 字符串替换、iOS字符串分隔、iOS之字符串匹配、截取字符串、匹配字符串、分隔字符串 ...

  • PHP中字符串函数库常用函数解析 -- PHP 学习 (十一)

    常用字符串函数分类: 字符串长度, 字符串查找, 字符串大小写转换, 字符串截取, 字符串 ASCII, 字符串加...

  • Kotlin语言(二):字符串类型

    1、字符串定义 2、字符串删除空格 3、字符串比较 4、字符串切割 5、字符串截取 6、字符串替换 7、字符串模板

  • 字符串扩展

    求字符串大小 字符串解码、转换 字符串截取 字符串汉字处理 字符串 Mac地址 字符串进制转换

  • 2020-09-30字符串

    day8-字符串 字符串的操作 in 和 not in字符串1 in 字符串2 - 判断字符串1是否是字符串...

网友评论

      本文标题:字符串

      本文链接:https://www.haomeiwen.com/subject/hmazjttx.html