/*
*Copyright (c) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称:Annpion.cpp
*作者:王耀鹏
*完成日期:2014年12月17日
*版本号:v1.0
*
*问题描述:用指针玩字符串。
*输入描述:不输入。
*程序输出:字符串去除空格。
*/
#include <iostream>
using namespace std;
char *delechar(char *str1);
int main()
{
char s1[50]="Hello world. ";
char s2[50]="Good morning. ";
char s3[50]="vegetable bird! ";
cout<<"未删除空格:"<<s1<<endl;
cout<<"删除空格后:"<<delechar(s1)<<endl;
cout<<"未删除空格:"<<s2<<endl;
cout<<"删除空格后:"<<delechar(s2)<<endl;
cout<<"未删除空格:"<<s3<<endl;
cout<<"删除空格后:"<<delechar(s3)<<endl;
return 0;
}
char *delechar(char *str1)
{
char *p;
int i=0;
for(p=str1;*(str1+i)!='\0';i++)
{
if(*(str1+i)!=' ')
*p++=*(str1+i);
}
*p='\0';
return str1;
}
运行结果: