当前位置:网站首页>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
}
边栏推荐
- Visual Studio调试技巧
- Pat class B 1016 C language
- Day_05 传智健康项目-预约管理-预约设置
- Leetcode topic resolution single number II
- jvm-04. Object's memory layout
- Cloud native database is the future
- [DaVinci developer topic] -41-app how SWC reads and writes NVM block data
- JVM原理简介
- Global attribute lang attribute
- 【DaVinci Developer专题】-41-APP SWC如何读取写入NVM Block数据
猜你喜欢

Activity startup mode and life cycle measurement results

Day_03 传智健康项目-预约管理-检查组管理

Learning Tai Chi Maker - esp8226 (11) distribution network with WiFi manager Library

(1)基础学习——vim编辑器常用快捷操作命令

Introduction to JVM principle

11、 Realization of textile fabric off shelf function

Design scheme of Small PLC based on t5l1

Day_ 13 smart health project - Chapter 13

Kotlin Android simple activity jump, simple combination of handler and thread

Explicability of counter attack based on optimal transmission theory
随机推荐
Pat class B 1026 program running time
Multiple strings for leetcode topic resolution
11、 Realization of textile fabric off shelf function
[focus on growth and build a dream for the future] - TDP year-end event, three chapters go to the Spring Festival!
pyinstaller 打包exe设置图标不显示
【Vivado那些事儿】XilinxCEDStore介绍
Pat class B 1018 C language
微软面试题:打印折纸的折痕
Day_07 传智健康项目-Freemarker
Machine learning 3-ridge regression, Lasso, variable selection technique
【Leetcode】431. Encode n-ary tree to binary tree (difficult)
[open source project] excel export Lua configuration table tool
Kotlin interface
Word pattern for leetcode topic analysis
Kotlin collaboration +retro most elegant network request use
Layer 2技术方案进展情况
SQL表名与函数名相同导致SQL语句错误。
App SHA1 acquisition program Baidu map Gaode map simple program for acquiring SHA1 value
[cocos2d-x] custom ring menu
Sorting out common problems after crawler deployment