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
Simple program to remove extra white spaces without using any inbuilt functions.
#include
#include
#include
using namespace std;
int main()
{
char str[1200];
int i,n,j,k, pos = 0 ;
cout<<"Enter string:\n";
gets(str);
n = strlen(str);
for(i =0;i<=n;i++)
{
if(str[i] == ' ')
{
for(j= i+1;j<=n;j++)
{
if(str[j] != ' ')
{
pos = j;
break;
}
}
if(pos != 0 && str[pos] != ' ')
{
for(k =i+1;k< pos;k++)
{ if(str[pos] == ' ')
break;
else{
str[k] = str[pos];
str[pos] = ' ';
pos++;
}
}
}
}
}
puts(str);
}