当前位置:网站首页>C language removes line breaks (or other characters) at the end of strings
C language removes line breaks (or other characters) at the end of strings
2022-06-23 06:34:00 【I have a magic box】
void main()
{
char now_mac[100];
strcpy(now_mac, "abcd\n"); // \0 End of string (strlen Not counting length ),\n For newline (strlen count 1 Length )
printf("%d\n", strlen(now_mac)); // Output 5
// now_mac[strlen(now_mac) - 1] = 0; // take \n Directly replace with 0 The effect is the same
now_mac[strlen(now_mac) - 1] = '\0'; // take \n Replace with \0
printf("%d\n", strlen(now_mac)); // Output 4
}
Reference link :
C Remove end of string newline ( Remove the last character of the string )
边栏推荐
- 把CSMA/CD、Token Bus、Token Ring说清楚
- vs+qt项目转qt creator
- [cocos2d-x] custom ring menu
- [DaVinci developer topic] -42- how to generate template and header files of APP SWC
- What is a PDCA cycle? How to integrate PDCA cycle and OKR
- C语言 踩坑:文档编码错误,导致base64中文编码错误
- There are so many code comments! I laughed
- Qt使用多线程编译项目的方法
- 学习太极创客 — ESP8226 (十一)用 WiFiManager 库配网
- golang正则regexp包使用-04-使用正则替换(ReplaceAll(),ReplaceAllLiteral(),ReplaceAllFunc())
猜你喜欢

Machine learning 3-ridge regression, Lasso, variable selection technique

(1) Basic learning - Common shortcut commands of vim editor

业务逻辑安全思路总结

Day_ 11 smart communication health project - graphic report and poi Report

什么是客户体验自动化?

mongodb 4. X binding multiple IP startup errors

Day_06 传智健康项目-移动端开发-体检预约

Progress of layer 2 technical scheme

Day_07 传智健康项目-Freemarker

JVM原理简介
随机推荐
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
Day_ 13 smart health project - Chapter 13
golang正则regexp包使用-04-使用正则替换(ReplaceAll(),ReplaceAllLiteral(),ReplaceAllFunc())
Day_ 11 smart communication health project - graphic report and poi Report
Day_02 传智健康项目-预约管理-检查项管理
Day_13 傳智健康項目-第13章
【踩坑记录】数据库连接未关闭连接,释放资源的坑
Possible pits in mongodb project
Xray linkage crawlergo automatic scanning pit climbing record
Day_11 传智健康项目-图形报表、POI报表
Global attribute lang attribute
Leetcode topic resolution single number II
记一次GLIB2.14升级GLIB2.18的记录以及其中的步骤原理
Summary of business logic security ideas
Laravel log channel grouping configuration
Tencent security 2021 report white paper collection (download attached)
C# wpf 通过绑定实现控件动态加载
去除防火墙和虚拟机对live555启动IP地址的影响
Redis sentry
图解 Google V8 # 18 :异步编程(一):V8是如何实现微任务的?