摘要: 1、函数原型 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) { char *tmp = s1; while(n) { if(!(*s1++ = *s2++)) //此处是if语句,不能用while、for等, 阅读全文
posted @ 2021-06-02 23:19 小鲨鱼2018 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 1、函数原型。 #include <stdio.h> char *strcpy(char *s1, const char *s2) { char *t = s1; while(*s1++ = *s2++) ; return t; } int main(void) { char str1[128] = 阅读全文
posted @ 2021-06-02 22:28 小鲨鱼2018 阅读(1622) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> char *mach(char *s, int key) { while(*s) { if(*s == key) return s; s++; } return NULL; } int main(void) { char str[128]; printf( 阅读全文
posted @ 2021-06-02 21:45 小鲨鱼2018 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int count(const char *s, int key) { int j = 0; while(*s) { if(*s == key) j++; s++; } return j; } int main(void) { char str[128]; 阅读全文
posted @ 2021-06-02 21:35 小鲨鱼2018 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> void put(const char *s) { while(*s) putchar(*s++); putchar('\n'); } int main(void) { char str[128]; printf("str: "); scanf("%s", 阅读全文
posted @ 2021-06-02 21:30 小鲨鱼2018 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 1、利用数组下标运算符 #include <stdio.h> int len(char s[]) { int len = 0; while(s[len]) len++; return len; } int main(void) { char str[128]; printf("str: "); sc 阅读全文
posted @ 2021-06-02 21:22 小鲨鱼2018 阅读(1051) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> char *copy(char *d, const char *s) { char *t = d; while(*d++ = *s++) ; return t; } int main(void) { char str1[] = "abcd"; char s 阅读全文
posted @ 2021-06-02 20:02 小鲨鱼2018 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 1、c语言中字符串的复制 #include <stdio.h> char *copy(char *d, const char *s) { char *t = d; // 定义指向传入的字符串首字符的指针 while(*d++ = *s++) //当指针s所指元素不为null时,将s所指元素赋值给d所 阅读全文
posted @ 2021-06-02 19:56 小鲨鱼2018 阅读(718) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { char s[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; int i; for(i = 0; i < 3; i++) { printf("s[%d] 阅读全文
posted @ 2021-06-02 18:00 小鲨鱼2018 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 1、原始程序,数组实现的字符串和指针实现字符串的不同点 #include <stdio.h> int main(void) { char *p = "123"; printf("first p = %s\n", p); p = "456"; printf("second p = %s\n", p); 阅读全文
posted @ 2021-06-02 17:21 小鲨鱼2018 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 1、strtoi #include <stdio.h> int strtoi(const char *s) { int i, j = 0; while(*s) { for(i = 0; i <= 9; i++) { if(*s - '0' == i) j = j * 10 + i; } s++; } 阅读全文
posted @ 2021-06-02 11:09 小鲨鱼2018 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> void del_num(char *s) //函数的形参为指针,也就是字符串数组的数组名,相当于指向数组第一个元素的指针。 { char *tmp = s; // 将指针tmp赋值为指针s,即指向传入的字符串数组的第一个元素的指针 while(*tmp) 阅读全文
posted @ 2021-06-02 08:07 小鲨鱼2018 阅读(38) 评论(0) 推荐(0) 编辑