Write a C++ Program to delete spaces from a sentence, where sentence is entered by the user.
Program Code:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str[80];
int i=0, len, j;
cout<<"Enter the sentence to delete space in it is: ";
gets(str);
cout<<endl;
len=strlen(str);
for(i=0; i<len; i++)
{
if(str[i]==' ')
{
for(j=i; j<len; j++)
{
str[j]=str[j+1];
}
len--;
}
}
cout<<"String after removing spaces in it is : ";
cout<<str;
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter the sentence to delete space in it is: Mukesh Rajput Mukesh
String after removing spaces in it is : MukeshRajputMukesh
Thanks
Mukesh Rajput
Post A Comment:
0 comments: