How To Remove Whitespaces In C++?

By: Prof. Dr. Fazal Rehman | Last updated: February 3, 2024

Algorithm of  Remove Whitespaces from source code:

  1. Input a string
  2. Finding the character of the white space  by using the while loop.
  3. Find the null character inside the loop, when encountered, we increment the index.
  4. Next, we input the remaining characters in the new string, “newstr”.
  5. Displaying the new string.

 

The logic of  Remove Whitespaces

Step 1: find out all nulls

Step 2:  ignore all the nulls in a string

Step 2:  store the remaining contents in another string.

 

C++ Code for Remove Whitespaces from the program

Write a C++ Program to delete whitespaces from the given string.

Output

Please Enter the string I LOVE T4TUTORIALS DOT COM

String after removal of blank spaces is: ILOVET4TUTORIALSDOTCOM

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials