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
Well here is a longish(but easy) solution that does not use pointers. It can be optimized further but hey it works.
#include
#include
using namespace std;
void removeExtraSpace(string str);
int main(){
string s;
cout << "Enter a string with extra spaces: ";
getline(cin, s);
removeExtraSpace(s);
return 0;
}
void removeExtraSpace(string str){
int len = str.size();
if(len==0){
cout << "Simplified String: " << endl;
cout << "I would appreciate it if you could enter more than 0 characters. " << endl;
return;
}
char ch1[len];
char ch2[len];
//Placing characters of str in ch1[]
for(int i=0; i