当前位置:网站首页>C language removes white space at the end of string
C language removes white space at the end of string
2022-06-09 16:28:00 【wangwei830】
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Remove trailing white space Include \t \n \r
/* Standard white space characters include : ' ' (0x20) space (SPC) Space character '\t' (0x09) horizontal tab (TAB) Horizontal tabs '\n' (0x0a) newline (LF) A newline '\v' (0x0b) vertical tab (VT) Vertical tabs '\f' (0x0c) feed (FF) Page identifier '\r' (0x0d) carriage return (CR) A carriage return //windows \r\n linux \n mac \r */
char *rtrim(char *str)
{
if (str == NULL || *str == '\0')
{
return str;
}
int len = strlen(str);
char *p = str + len - 1;
while (p >= str && isspace(*p))
{
*p = '\0';
--p;
}
return str;
}
int main(){
char dbsname[] = "abc1 23 ";
char *c;
int m ;
for ( m=0; m<20 ;m++){
c=&dbsname[m];
printf("%c,%d-------\n",*c,*c);
}
printf("%s",dbsname);
char *p = rtrim(dbsname);
printf("%s\n",p);
for ( m=0; m<20 ;m++){
printf("%c,%d-------\n",*p,*p);
p++;
}
}
边栏推荐
猜你喜欢

Test must see, key points of writing test cases for the first time

The interviewer asked me how many locks were added to an update statement? I summarized the whole eight part essay

10 questions that must be asked in software testing interview

JPEX推出BAYC MAYC合约系列 欢迎体验

30-year-old mind map

数据库存储目录结构简介

Dapr source code analysis | basic introduction

10个必备的AutoCAD插件

After reading it, I will analyze the whole process from packet capturing to interface testing

Nth child selector
随机推荐
应用软件效率测试的执行策略
Dapr source code analysis | basic introduction
面试官问我一条update语句加了多少锁?我总结了全套八股文
Analysis of variable hiding security in contract security
Ffmpeg mind map
ASEMI的MOS管9N90参数,9N90电路图,9N90实物图
容器和镜像的区别
618's money saving technology strategy is coming - experience the scene and get a 10 yuan cat super card!
Reconstruction essentials learning
Rapid development template based on ABP vNext
30-year-old mind map
Build an integrated intelligent dialogue analysis platform from intelligent quality inspection to dialogue analysis, and the customer service center of Bank of Hangzhou creates a new business card of
检测ip地址库内是否存在指定的ip
Nth child selector
在不平衡数据上使用AUPRC替代ROC-AUC
使用ffmpeg合并mp4文件
测试必看,初次编写测试用例的要点
姑娘,你为什么要编程呢
php常用日期相关函数
Differences between single application and microservice invocation