当前位置:网站首页>字符处理函数
字符处理函数
2022-07-17 05:08:00 【学会放下ta】
string.h函数使用
#1.strlen(char*)
这个函数功能是读取字符串的长度,读到第一个’\0’结尾。不包含’\0’,注意与sizeof区分。(sizeof是读取字符串所在的储存空间大小)返回值是一个无符号整数,所以比较字符串大小用大于小于,不要相减看正负。
2.strcpy(char*,char*)
作用:把后者复制到前者,他会把字符串结束标志’\0’一起复制,短的复制到长的里面只会打印短的,长的后半截不会打印
char str1[100] = "Original";
char str2[10] = "New";
strcpy(str1, str2);
printf("%s\n", str1);
例如这里打印New,而不是Newginal
3.strncat(char*,char*,int)
指定取多少个字符连接到前者末尾,在int后一个位置加的’\0’
4.strncpy(char*,char*,int)
复制后不会自动添加’\0’
5.strncmp(char* str1,char* str2,int)
比较字符串大小,如果返回值 < 0,则表示 str1 小于 str2。
如果返回值 > 0,则表示 str2 小于 str1。
如果返回值 = 0,则表示 str1 等于 str2。
加点东西:
如何获取二维数组的长度?
最好的方法没有之一:sizeof(a) / sizeof(a[0][0])
注意事项:a[4][3]既可表示4行3列也可表示3行4列,因为储存结构一样都是连续12个空间,怎么用看个人习惯。
边栏推荐
猜你喜欢

web3js开发技术

MySQL transactions

Redis source code analysis dynamic string implementation (SDS)

Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr

用Flink SQL流化市场数据2:盘中风险价值

线程池如何监控,才能帮助开发者快速定位线上错误?

分布式存储-fastdfs

Buuctf miscellaneous - QR code

How to deal with the mismatch between subtitle files and video files

Distributed storage fastdfs
随机推荐
Performance bottleneck finding - Flame graph analysis
[first launch in the whole network] one month later, we switched from MySQL dual master to master-slave
聊聊写代码的20个反面教材
Cesium 绑定鼠标事件和移除鼠标事件
Flex弹性布局
新手学习渗透测试的入门指南
MySQL - index
路由器loopback口实验
Swagger configuration and use
性能瓶颈查找-火焰图分析
Cesium BIND Mouse Events and remove Mouse Events
MySQL--存储和游标
MYSQL基本语法字典
Distributed registry etcd
Data Lakehouse的未来-开放
markdown笔记以及Typora相关快捷键
在 CDP中使用Iceberg 为数据湖仓增压
交换机用户模式、特权模式、全局模式、端口模式
Distributed storage fastdfs
Easypoi之excel简单导出