Tyler Treat Tyler Treat - 1 year ago 106
C Question

Removing Spaces from a String in C?

What is the easiest and most efficient way to remove spaces from a string in C?

Answer Source

Easiest and most efficient don't usually go together...

Here's a possible solution (untested):

void RemoveSpaces(char* source)
  char* i = source;
  char* j = source;
  while(*j != 0)
    *i = *j++;
    if(*i != ' ')
  *i = 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download