C++ Programming Code Examples C++ > Strings Code Examples Programming Code to Remove or Delete Spaces from String or Sentence Programming Code to Remove or Delete Spaces from String or Sentence 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. Following C++ program ask to the user to enter any sentence or string to remove spaces from the sentence or string, then display the string or sentence after removing the spaces: #include<iostream.h> #include<conio.h> #include<stdio.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; cout << "C++ Programming Language | Happy Codings :)"; getch(); }