C++ program to delete white space between words


Source Code :

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

void deletespace(char*);

void main()
{
clrscr();
char string[100];
cout<<"\nEnter the String : ";
gets(string);
deletespace(string);
getch();
}

void deletespace(char str[])
{
 int i=0,j=0;
 int length = strlen(str);
 cout<<"Before : ";puts(str);
 for(i=0;i<length;i++)
 {

A : if(str[i]==' ')
{

for(j=i;j<length;j++)
str[j]=str[j+1];
goto A;
continue;
}
}
 cout<<"After : ";puts(str);
}

Comments