/*删除字符串中的空格*/
#include<iostream.h>
#include<string.h>
void main()
{
char a[100];
int i,j;
cout<<"please input chars:";
cin.getline(a,100); //输入字符的一种形式,可把空格记录在内
for(j=0;j<=strlen(a);j++) //strlen(a)计算字符所占长度
{
switch(a[j]) //用for语句逐个比较数组元素
case' ':{
for(i=j;i<=strlen(a);i++) //找到空格后把数组j以后的元素向前移一位
a[i]=a[i+1];
--j; //把数组下标向前移一位,避免遗漏所要比较的数组元素
}
}
for(j=0;j<=strlen(a);j++) //用for逐个输出字符
cout<<a[j];
cout<<endl;
}
#include<iostream.h>
#include<string.h>
void main()
{
char a[100];
int i,j;
cout<<"please input chars:";
cin.getline(a,100); //输入字符的一种形式,可把空格记录在内
for(j=0;j<=strlen(a);j++) //strlen(a)计算字符所占长度
{
switch(a[j]) //用for语句逐个比较数组元素
case' ':{
for(i=j;i<=strlen(a);i++) //找到空格后把数组j以后的元素向前移一位
a[i]=a[i+1];
--j; //把数组下标向前移一位,避免遗漏所要比较的数组元素
}
}
for(j=0;j<=strlen(a);j++) //用for逐个输出字符
cout<<a[j];
cout<<endl;
}