C語言:使用指標法,刪除字串的所有尾部空格
阿新 • • 發佈:2019-02-19
題目來源:大工慕課 連結
作者: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;
}