网站规划与设计方向,免费商标图案 创意,东营网站设计制作,开发公司已开发完成楼盘土地证能否出让文章目录 C语言开发#xff0c;指针进阶。1.字符串与指针的关系2.指针获取字符串具体内容3.字符串比较#xff0c;查找#xff0c;包含#xff0c;拼接4.字符串大小写 C语言开发#xff0c;指针进阶。
1.字符串与指针的关系
//
// Created by MagicBook on 2023-10-22.
… 文章目录 C语言开发指针进阶。1.字符串与指针的关系2.指针获取字符串具体内容3.字符串比较查找包含拼接4.字符串大小写 C语言开发指针进阶。
1.字符串与指针的关系
//
// Created by MagicBook on 2023-10-22.
//
#include stdio.hint main11() {char str[] {d, 1, s,\0};//str数组的字符串是存在全局区静态区域修改的时候拷贝一份到main函数的栈区再进行修改操作str[1] a;//printf遇到\0结束printf(%s\n, str);//开辟内存地址指向静态区域里面的aaaa,指针不能修改静态全局区域内的字符串内容char *str2 aaaa;//崩溃str2[1] 2;return 0;
}2.指针获取字符串具体内容
//
// Created by MagicBook on 2023-10-22.
//
#include stdio.hint main11() {char str[] {d, 1, s,\0};//str数组的字符串是存在全局区静态区域修改的时候拷贝一份到main函数的栈区再进行修改操作str[1] a;//printf遇到\0结束printf(%s\n, str);//开辟内存地址指向静态区域里面的aaaa,指针不能修改静态全局区域内的字符串内容char *str2 aaaa;//崩溃str2[1] 2;return 0;
}//
// Created by MagicBook on 2023-10-22.
//
#include stdio.hint getLen(char *string) {int cnt 0;//移动指针 不等于\0一直循环while (*string) {string;cnt;}return cnt;
}//数组作为参数传递会把数组优化成指针
void getLen2(int *res, int arr[]) {/* int len sizeof(arr) / sizeof(int);printf(%d\n, len);*/int cnt 0;while (*arr) {arr;cnt;}*res cnt;
}int main() {char str[] {d, 1, s, \0};int len getLen(str);printf(%d\n, len);int arr[] {1, 2, 3, \0};int len2 sizeof(arr) / sizeof(int);int res;getLen2(res, arr);printf(%d\n, len2);return 0;
}3.字符串比较查找包含拼接
//
// Created by MagicBook on 2023-10-22.
//
#include stdio.h
#include stdlib.h
#include string.hint main() {//字符串转换char *aaa 1222;int res atoi(aaa);//true不等于0if (res) {printf(%d\n, res);} else {printf(----);}//doubledouble res2 atof(aaa);printf(%lf\n, res);//字符串比较char *string1 aaa;char *string2 aaasss;//区分大小写int ress strcmp(string1, string2);//不区分大小写int resss stricmp(string1, string2);//0是相等非0不相等if (!ress) {printf(yes);} else {printf(no);}return 0;
}//
// Created by MagicBook on 2023-10-22.
//
#include stdio.h
#include stdlib.h
#include string.hint main() {char *aa 1234;char *aaa 1;char *test strstr(aa, aaa);//非NULL进ifif (test) {printf(%s\n, test);} else {}//包含if (test) {} else {}//取位置int index test - aa;//拼接字符串char test1[22];char *a1 11, *a2 22, *a3 33;//先拷贝到数组容器中再拼接字符串strcpy(test1, a1);strcat(test1, a2);strcat(test1, a3);return 0;
}4.字符串大小写
//
// Created by MagicBook on 2023-10-22.
//
#include stdio.h
#include stdlib.h
#include string.h
#include ctype.hvoid low(char *b, char *c) {while (*c) {*b tolower(*c);//移动指针c;//一边移动一边存储。b;}*b \0;
}int main() {//都变成小写char *a qDHaAA;//char test[20];low(test, a);return 0;
}