Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Language/C++/Remove white spaces from string
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#include <iostream>
using namespace std;

// Function to remove all spaces from a given string
void removeSpaces(char *str)
{
// To keep track of non-space character count
int count = 0;


for (int i = 0; str[i]; i++)
if (str[i] != ' ')
str[count++] = str[i]; // here count is
// incremented
str[count] = '\0';
}

// Driver program to test above function
int main()
{
char str[] = "g eeks for ge eeks ";
removeSpaces(str);
cout << str;
return 0;
}