随笔分类 -  c/c++

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页
摘要: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 阅读(1212) 评论(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 阅读(46) 评论(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 阅读(889) 评论(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 阅读(61) 评论(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 阅读(97) 评论(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 阅读(69) 评论(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 阅读(58) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> void del(char *str) { while(*str) { if(*str >= '0' && *str <= '9') printf(""); else putchar(*str); str++; } } int main(void) { c 阅读全文
posted @ 2021-06-01 22:15 小鲨鱼2018 阅读(44) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> #include <ctype.h> void str_toupper(char *s) { while(*s) { *s = toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s 阅读全文
posted @ 2021-06-01 21:44 小鲨鱼2018 阅读(38) 评论(0) 推荐(0)
摘要:1、c语言中转换字符串函数 atoi将字符型转换为int型。 c语言标准函数库提供了字符串转换函数。 <stdlib.h>。 #include <stdio.h> #include <stdlib.h> //c语言标准函数库 int main(void) { char str[128]; print 阅读全文
posted @ 2021-06-01 21:29 小鲨鱼2018 阅读(378) 评论(0) 推荐(0)
摘要:1、函数原型。 #include <stdio.h> int strncmp(const char *s1, const char *s2, size_t n) //函数返回int型,形参为两个指向char型的指针)和 unsigned 型n。 { while(n && *s1 && *s2) // 阅读全文
posted @ 2021-06-01 20:15 小鲨鱼2018 阅读(1776) 评论(0) 推荐(0)
摘要:1、函数原型。 #include <stdio.h> int strcmp(const char *s1, const char *s2) // 函数返回int型,形参为两个指向char型的指针 { while(*s1 == *s2) //当元素相等时 { if(*s1 == '\0') // 判断 阅读全文
posted @ 2021-06-01 18:31 小鲨鱼2018 阅读(1913) 评论(0) 推荐(0)
摘要:1、函数原型 #include <stdio.h> char *strncat(char *s1, const char *s2, size_t n) //函数的返回值为指向char型的指针,形参为两个指针(函数间数组(字符串数组)的传递是以指向数组第一个元素的指针进行的)和正整数n。 { char 阅读全文
posted @ 2021-06-01 11:29 小鲨鱼2018 阅读(300) 评论(0) 推荐(0)
摘要:1、函数原型 #include <stdio.h> char *strcat(char *s1, const char *s2) //函数返回类型为指针,形参为两个指针(为字符串数组的数组名,相当于指向数组第一个元素的指针) { char *tmp = s1; //将指针tmp赋值为s1指针,也就是 阅读全文
posted @ 2021-06-01 10:21 小鲨鱼2018 阅读(1812) 评论(0) 推荐(0)
摘要:1、函数原型。 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) //函数的返回值为指针,形参为两个指针(字符串数组,相当于指向第一个字符的指针)和n(赋值字符个数)。 { char *tmp = s1; //将 阅读全文
posted @ 2021-06-01 09:49 小鲨鱼2018 阅读(1796) 评论(0) 推荐(0)
摘要:1、函数原型(字符串的复制) #include <stdio.h> char *strcpy(char *s1, const char *s2) //函数的返回值为指向char型的指针, 形参为指向char型的指针 { char *tmp = s1; // 将指针tmp声明为s1,s1为传入的字符串 阅读全文
posted @ 2021-06-01 09:21 小鲨鱼2018 阅读(1706) 评论(0) 推荐(0)
摘要:1、函数原型(利用指针求字符串的长度) #include <stdio.h> size_t strlen(const char *s) //函数头的形参为常数的、指向char型的指针,也就是接收的形参为指针(实际上传入的是字符串数组,函数间数组的传递实际上是通过指向第一个元素的指针完成的) { // 阅读全文
posted @ 2021-06-01 08:57 小鲨鱼2018 阅读(2535) 评论(0) 推荐(0)
摘要:1、函数原型。 #include <stdio.h> char *strncat(char *s1, const char *s2, size_t n) // 这里的cat指的是:concatenate { char *tmp = s1; while(*s1) s1++; while(n--) if 阅读全文
posted @ 2021-05-31 22:59 小鲨鱼2018 阅读(447) 评论(0) 推荐(0)
摘要:c语言中strcat函数。 1、函数原型。 #include <stdio.h> char *strcat(char *s1, const char *s2) { char *tmp = s1; while(*s1) s1++; while(*s1++ = *s2++) ; return tmp; 阅读全文
posted @ 2021-05-31 22:26 小鲨鱼2018 阅读(862) 评论(0) 推荐(0)
摘要:1、函数原型。 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) { char *tmp = s1; while(n) { if(!(*s1++ = *s2++)) break; n--; } while(n-- 阅读全文
posted @ 2021-05-31 21:52 小鲨鱼2018 阅读(653) 评论(0) 推荐(0)

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页