
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Remove Spaces from a String in C++
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; }
Advertisements