di/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:main.cpp
* 作 者:孔云
* 完成日期:2013年12月20日
* 版 本 号: v1.0
* 输入描述:指针法去除句子中多余空格。
* 问题描述:深刻学习编程思路。
*/
#include<iostream>
using namespace std;
void palltrim( char *str);
int main()
{
char s[90]="Hello !Neice too meet you";
palltrim(s);
cout<<"整理后的句子:"<<s;
return 0;
}
void palltrim( char *st)
{
bool nospace;
int i=0,j=0;
while(*(st+i)==' ')
i++;
nospace=true;
while(*(st+i)!='\0')
{
if(*(st+i)!=' ')
{
nospace=true;
*(st+j)=*(st+i);
i++;
j++;
}
else if(nospace)
{
nospace=false;
*(st+j)=*(st+i);
i++;
j++;
}
else
{
i++;
}
}
*(st+j)='\0';
}
心得体会:这个程序,我、、、我、、、、很生气、、、、