In another post I shown how to remove leading and trailing white spaces from a char* in C, this time I’m going to show a simple function to remove white spaces inside the char*.

void emptySpaces(char* my_string)
{
	char* c = my_string;
	char* k = my_string;
	while(*k != 0)
	{
		*c = *k++;
		if(*c != ' ')
			c++;
	}
	*c = 0;
}

The above function removes spaces and modifies the source string. If you want the source string unmodified you can copy the source into a destination char by char skipping white spaces.

void emptySpaces1(char* source, char *destination)
{
	int i;
	int j = 0;
	for(i=0; i<strlen(source), i++)
	{
		if(source[i]!=' ')
		{
			destination[j] = source[i];
			j++;
		}
	}
}

To call emptySpaces1 you have to allocate a destination string of the same size of the source one.

Gg1.