Write a C++ Programming to remove spaces from String.

Program Code:
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char str[80];
int i=0, length, j;
cout<<"Enter the String : ";
gets(str);
cout<<endl;
length = strlen(str);
for(i=0; i<length; i++)
{
if(str[i]==' ')
{
for(j=i; j<length; j++)
{
str[j]=str[j+1];
}
length--;
}
}
cout<<"String after removing spaces = ";
cout<<str;
return 0;
}


The program output is tested on www.jdoodle.com
Output:
Enter the String : Muk esh Raj put
String after removing spaces = MukeshRajput


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: