#include <string.h>
#include <stdio.h>
//删除字符串尾部的空格符、制表符与换行符,并返回最后一个字符的下标
int trim(char s[])
{
int n;
for(n = strlen(s) - 1;n >= 0;n--)
if(s[n] != ' '&& s[n] != '\t'&&s[n] !='\n')
break;
s[n+1] = '\0';
return n;
}
int main()
{
int n;
char s[10] = {'2','s','q','w','2',\0'};
n = trim(s);
printf("%d",n);
return 0;
}
trim函数的编写
最新推荐文章于 2022-03-17 07:12:52 发布