- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Programs for practice
To remove or delete spaces from the string or sentence, you have to ask to the user to enter a string. Now start checking for spaces. If space will be found, then start placing the next character from the space to the back until the last character and continue to check for next space to remove all the spaces present in the string as shown here in the following program.
Source Code: Remove Spaces from String
/* C++ Program - Remove Spaces from String */ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { clrscr(); char str[80]; int i=0, len, j; cout<<"Enter the String : "; gets(str); 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 = "<<str; getch(); }Output
Enter the String : Hello How Are You String after removing spaces = HelloHowAreYou