Trim leading spaces on a string (without returning a new string)
I wrote a quick function to trim trailing spaces on a string without generating a new string...
Code:
void rtrim (char * s ) {
int end;
end = strlen(s) - 1;
if (end >= 0 && s[end] == '\n')
s[end] = '\0';
}
Doing it on leading spaces is more complicated. I particularly don't want something that generates a new string. Something I can call like this:
I can't be the first person to do this - rather than invent the wheel, does someone have code or a pointer to some code?
I'm thinking something that uses memmove() would be the solution...? Or perhaps there's a different technique...?