当前位置:网站首页>C语言去除字符串尾部的换行(或其他字符)
C语言去除字符串尾部的换行(或其他字符)
2022-06-23 04:41:00 【我有一个魔盒】
void main()
{
char now_mac[100];
strcpy(now_mac, "abcd\n"); // \0为字符串结尾(strlen不算长度),\n为换行(strlen算1个长度)
printf("%d\n", strlen(now_mac)); // 输出5
// now_mac[strlen(now_mac) - 1] = 0; // 将\n直接替换成0效果相同
now_mac[strlen(now_mac) - 1] = '\0'; // 将\n替换为\0
printf("%d\n", strlen(now_mac)); // 输出4
}
边栏推荐
- Leetcode topic resolution single number
- Pyqt5 setting window top left Icon
- [vivado] xilinxcedstore introduction
- Visual Studio调试技巧
- Detailed explanation of redis persistence, master-slave and sentry architecture
- 去除防火墙和虚拟机对live555启动IP地址的影响
- Addressing and addressing units
- Day_07 传智健康项目-Freemarker
- Pat class B 1022 d-ary a+b
- 【开源项目】excel导出lua配置表工具
猜你喜欢
随机推荐
Redis sentry
[database backup] complete the backup of MySQL database through scheduled tasks
exe闪退的原因查找方法
【Cocos2d-x】自定义环形菜单
Pat class B 1010 C language
去除防火墙和虚拟机对live555启动IP地址的影响
(1) Basic learning - Common shortcut commands of vim editor
论文笔记: 多标签学习 LSML
Cloud native database is the future
Leetcode topic resolution single number II
App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
[vivado] xilinxcedstore introduction
Given a node of a binary tree, return the successor node of the node
(1)基础学习——vim编辑器常用快捷操作命令
Visual studio debugging tips
Find the number of nodes in the widest layer of a binary tree
微软面试题:打印折纸的折痕
Summary of ant usage (I): using ant to automatically package apk
Pyqt5 设置窗口左上角图标
pyinstaller 打包exe设置图标不显示



![[cocos2d-x] screenshot sharing function](/img/fc/e3d7e5ba164638e2c48bc4a52a7f13.png)





