Answer by Hedgehog Mind for Remove extra white spaces in C++
I don't know if this helps but this is how I did it on my homework. The only case where it might break a bit is when there is spaces at the beginning of the string EX " wor ds " In that case, it will...
View ArticleAnswer by Galik for Remove extra white spaces in C++
You can use std::unique which reduces adjacent duplicates to a single instance according to how you define what makes two elements equal is.Here I have defined elements as equal if they are both...
View ArticleAnswer by Jan for Remove extra white spaces in C++
I ended up here for a slighly different problem. Since I don't know where else to put it, and I found out what was wrong, I share it here. Don't be cross with me, please.I had some strings that would...
View ArticleAnswer by Hans for Remove extra white spaces in C++
Well here is a longish(but easy) solution that does not use pointers.It can be optimized further but hey it works.#include <iostream>#include <string>using namespace std;void...
View ArticleAnswer by Peter - Reinstate Monica for Remove extra white spaces in C++
I have the sinking feeling that good ol' scanf will do (in fact, this is the C school equivalent to Anatoly's C++ solution):void remove_extra_whitespaces(char* input, char* output){ int srcOffs = 0,...
View ArticleAnswer by Christophe for Remove extra white spaces in C++
There are already plenty of nice solutions. I propose you an alternative based on a dedicated <algorithm> meant to avoid consecutive duplicates: unique_copy(): void remove_extra_whitespaces(const...
View ArticleAnswer by villapx for Remove extra white spaces in C++
Here's a simple, non-C++11 solution, using the same remove_extra_whitespace() signature as in the question:#include <cstdio>void remove_extra_whitespaces(char* input, char* output){ int...
View ArticleAnswer by Jts for Remove extra white spaces in C++
Since you are writing c-style, here's a way to do what you want.Note that you can remove '\r' and '\n' which are line breaks (but of course that's up to you if you consider those whitespaces or...
View ArticleAnswer by Lol4t0 for Remove extra white spaces in C++
for in-place modification you can apply erase-remove technic:#include <string>#include <iostream>#include <algorithm>#include <cctype>int main(){ std::string input {"asfa sas f...
View ArticleAnswer by anatolyg for Remove extra white spaces in C++
Since you use C++, you can take advantage of standard-library features designed for that sort of work. You could use std::string (instead of char[0x255]) and std::istringstream, which will replace most...
View ArticleAnswer by Ami Tavory for Remove extra white spaces in C++
There are plenty of ways of doing this (e.g., using regular expressions), but one way you could do this is using std::copy_if with a stateful functor remembering whether the last character was a...
View ArticleRemove extra white spaces in C++
I tried to write a script that removes extra white spaces but I didn't manage to finish it. Basically I want to transform abc sssd g g sdg gg gf into abc sssd g g sdg gg gf.In languages like PHP or C#,...
View Article