C++ Program to Delete White Spaces from String
Write C++ Program to Delete White Spaces from String
// CPP Program to Delete White Spaces from String #include <iostream> #include <string.h> #include <stdlib.h> using namespace std; int main() { char S[50]; int i = 0; cout << "Enter String :--> "; gets(S); int n = strlen(S); while(i < n) { if(S[i] == ' ') { int j = i; while(j < n-1) { S[j] = S[j + 1]; j++; } n--; i--; } i++; } S[i]='\0'; cout << "\nString After Removal of White Space :--> " << S; return 0; }
Output:
Enter String :--> Hi, Hello and Welcome to CodeCrucks
String After Removal of White Space :--> Hi,HelloandWelcometoCodeCrucks