I'm new to programing and i have to make a program in which you enter a sentence and remove any repeating characters like space, commas and so on. So my idea was to print only the characters that match my criteria. But i get a problem like this :
input : "This is(5 spaces for example) a (2 spaces) sample (3spaces)sentence".
but the output is :"This",instead of "This is a sample sentence"
My code is:
#include <iostream>
#include <string.h>
using namespace std;
int const l=200;
int main ()
{
char a[l];
cin >> a;
int d;
d=strlen (a);
int i = 0;
for(i = 0; i < d; i++)
{
if(a[i] != ' ' && a[i+1] != ' ')
{
cout<<a[i];
}
}
}
It would be nice if you tell me what my mistake is and how to solve it.Thanks in advance.