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
Post A Comment:
0 comments: