C code to remove spaces from a string

Write a C function to remove spaces from a string. The function header should be
void removeSpaces(char *str)

ie, “abc de” -> “abcde”

C++:
01 void removeSpace(char*& s)
02 {
03     int slow=0,fast=0;
04     while(s[fast]!=){
05         if(s[fast]==‘ ‘)
06             fast++;
07         else
08             s[slow++]=s[fast++];
09     }
10     s[slow++]=;
11 }
Advertisements
This entry was posted in String. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s