摘要:
1、 #include <stdio.h> int str_c(const char *x, int key) { int j = 0; while(*x) { if(*x == key) j++; x++; } return j; } int main(void) { char str[128]; 阅读全文
posted @ 2021-05-31 19:24
小鲨鱼2018
阅读(49)
评论(0)
推荐(0)
摘要:
1、 #include <stdio.h> void put_string(const char *s) // 传入的实参为指针,在数组中,指向首个字符的指针的行为和数组本身一样。 { printf("%s\n", s); // 显示数组本身。 } int main(void) { char str 阅读全文
posted @ 2021-05-31 16:50
小鲨鱼2018
阅读(69)
评论(0)
推荐(0)
摘要:
1、利用数组。 #include <stdio.h> int len(char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str[128]; printf("str = "); scanf 阅读全文
posted @ 2021-05-31 16:41
小鲨鱼2018
阅读(478)
评论(0)
推荐(0)
摘要:
1、 #include <stdio.h> char* copy_str(char *d, const char *s) { char *t = d; while(*d++ = *s++) ; return t; } int main(void) { char str[128] = "ABCD"; 阅读全文
posted @ 2021-05-31 16:15
小鲨鱼2018
阅读(87)
评论(0)
推荐(0)
摘要:
c语言中字符串的复制。 1、 #include <stdio.h> char* str_copy(char *d, const char *s) //函数的返回值为指向char型的指针型, 形参为两个指向char型的指针。 { char *t = d; // 指针t等于指针d,指针d为指向字符串第一 阅读全文
posted @ 2021-05-31 16:02
小鲨鱼2018
阅读(927)
评论(0)
推荐(0)
摘要:
c语言中利用数组、指针实现字符串、字符串数组。 1、字符串 #include <stdio.h> int main(void) { char x[] = "abcd"; //数组实现字符串 ,x一般解释为指向数组第一个元素的指针 char *y = "xyz"; //指针实现字符串 ,y为指向一个字 阅读全文
posted @ 2021-05-31 11:13
小鲨鱼2018
阅读(741)
评论(0)
推荐(0)
摘要:
c语言中显示字符串数组的长度(数组实现的字符串数组和指针实现的字符串数组) 1、 #include <stdio.h> int main(void) { char x[][128] = {"aaa","bb","cccccc","d","eee"}; char *y[] = {"11111","22 阅读全文
posted @ 2021-05-31 11:01
小鲨鱼2018
阅读(780)
评论(0)
推荐(0)
摘要:
c语言中判断字符串的长度,利用数组和利用指针。 1、利用数组。 #include <stdio.h> int len(const char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str 阅读全文
posted @ 2021-05-31 10:55
小鲨鱼2018
阅读(1916)
评论(0)
推荐(0)
摘要:
1、 #include <stdio.h> int main(void) { int i; char a[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; printf("sizeof(a) = %u\n", sizeof(a)); 阅读全文
posted @ 2021-05-31 09:39
小鲨鱼2018
阅读(70)
评论(0)
推荐(0)