用c语言指针编写程序,删除字符串的所有尾部空格

如题所述

#include <stdio.h>
#include <string.h>

void modify(char *str) //去空格函数
{
int i = strlen(str);
while(str[i-1]==' ')
{
str[i] = '\0';
i--;
}
str[i] = '\0';
}
void main()
{
char s[] = "SSSS s s@#$ ";
printf("first: %s", s);
puts("###"); //标记作用
modify(s);
printf("second: %s", s);
puts("###"); //标记作用
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-01
//---------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char a[80];
int i;
gets(a);/*输入字符串*/

i=strlen(a)-1; /*去末尾空格*/
while (isspace(a[i]))
--i;
a[i+1]='\0';

puts(a); /*输出去空格之后的字符串*/
return 0;
}
//---------------------------------------------------------------------------

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网