题目来源:大工慕课 链接
作者:Caleb Sung
题目要求
按照要求补完程序,使用指针法,删除字符串的所有尾部空格。
要求:在begin 和 end 之间填写程序,其他不得改动。
如:
【输入】c language <回车>
【输出】
the length of input string is 14
c language
the length of output string is 10
参考代码
#include<stdio.h>
#include <string.h>
int main()
{
char s1[100],*p;
printf("input a line of strings\n");
gets(s1);
printf("the length of input string is %d\n",strlen(s1));
/******** begin **************/
for(p=s1;p<=s1+strlen(s1);p++)
if(*p==' ')
*p='\0';
/******** end **************/
puts(s1);
printf("the length of output string is %d\n",strlen(s1));
return 0;
}