

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to remove spaces from a string?
The program takes a string and removes the spaces in it. This is useful when we want to save the space of our The following sample shows how it is done with an explanation.
Input: Hello World Output: HelloWorld
Explanation
To remove or delete spaces from the string or sentence, you have to ask 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 the next space to remove all the spaces present in the string
Example
#include <iostream> #include<string.h> using namespace std; int { char str[80]="Hello World"; int i=0, len, j; 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 << str; return 0; }
- Related Questions & Answers
- Java Program to remove all white spaces from a String.
- Java program to remove all the white spaces from a given string
- Remove spaces from std::string in C++
- C program to remove extra spaces using string concepts.
- C program to remove spaces in a sentence using string concepts.
- How to remove double or more spaces from a string in MySQL?
- Remove extra spaces in string JavaScript?
- How to remove all special characters, punctuation and spaces from a string in Python?
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- C# Program to split a string on spaces
- Java Program to Remove All Whitespaces from a String
- Trim a string in Java to remove leading and trailing spaces
- Trim (Remove leading and trailing spaces) a string in C#
- Removing all spaces from a string using JavaScript
- C# program to remove n-th character from a string
Advertisements