I have a string representing an integer with spaces -- digits are grouped by three.
I was considering using strchr
and strcat
, as in:
char* remove_spaces (char* s)
{
char* space;
while (space = strchr(s, ' '))
{
*space = '\0';
strcat(s, space + 1);
}
return s;
}
But, first, I'm not sure it is safe to use strcat
this way since the string to be appended overlaps the final string.
Next, I'm wondering whether this could be done better with something like sscanf
.