C++去掉字符串中重复空格
2016-08-12 14:53
447 查看
#include<iostream>
#include<string.h>
using namespace std;
void delSpace(char* buf)
{
//int len = strlen(buf);
//int i,j;
//if(i = 0; i < len;i++)
char* fast = buf;
char* temp = buf;
while(*fast!='\0')
{
if(*fast!=' ')
{
*temp=*fast;
temp++;
fast++;
}
else
{
while(*fast == ' ')
fast++;
//cout<<*fast;
*temp=' ';
temp++;
}
}
*temp='\0';
}
int main()
{
char s[100];
int i = 0;
cin.getline(s,100);
delSpace(s);
i=0;
while(1)
{
if(s[i]=='\0')
break;
else
cout<<s[i];
i++;
}
return 0;
}
#include<string.h>
using namespace std;
void delSpace(char* buf)
{
//int len = strlen(buf);
//int i,j;
//if(i = 0; i < len;i++)
char* fast = buf;
char* temp = buf;
while(*fast!='\0')
{
if(*fast!=' ')
{
*temp=*fast;
temp++;
fast++;
}
else
{
while(*fast == ' ')
fast++;
//cout<<*fast;
*temp=' ';
temp++;
}
}
*temp='\0';
}
int main()
{
char s[100];
int i = 0;
cin.getline(s,100);
delSpace(s);
i=0;
while(1)
{
if(s[i]=='\0')
break;
else
cout<<s[i];
i++;
}
return 0;
}
相关文章推荐
- c++去掉字符串中连续的空格,只保留一个
- C++去掉字符串中首尾空格和所有空格
- C++中去掉string字符串中的空格和tab
- 一个C#面试问题,要求是将字符串中重复字符从第二个开始都去掉,空格除外。然后显示的时候,从后往前显示。
- C/C++ 去掉字符串首尾空格函数
- C/C++ / string 字符串去掉左右空格
- C#练习——去掉字符串两端的空格、统计字符出现的次数及出现的索引位置、随机生成10个1-100之间的不重复的偶数
- C++ 去掉字符串的首尾空格和全部空格
- js正则去掉字符串中空格和重复字符串
- C++去掉字符串首尾的 空格 换行 回车
- C/C++ 去掉字符串首尾空格函数
- C/C++ / string 字符串去掉左右空格
- C/C++学习之C提高-----非空格的字符串长度、去掉字符串前后空格、字符串反转、键值对字符串、const练习、二级指针做输入/输出的特性、将字符串按逗号分开,并放入二维数组打印出来
- java 去掉字符串的空格(中间空格,左右空格)
- javascript里的 不等于 的符号、 去掉字符串首尾空格
- 两列字段,合并成一个字符串,并且中间加一个符号,并去掉所有的空格
- 实现javascript中去掉字符串前后空格
- js去掉字符串全部空格
- ASP去掉字符串头尾连续回车和空格的Function
- 去掉字符串中重复的子字符串