Code:
while (*start && *start == ' ') start++;
The first condition is unnecessary. If *start is a space then there's no need to check if *start is non-zero. I'd just do:
Code:
while (*start == ' ') start++;
Code:
while (*end && *end == ' ') end--;
You're working backwards through the string so *end will never be zero (as long as you're still pointing to somewhere within the string). Instead you want to make sure that end is greater than inputStr to avoid running past the beginning of the string. I'd write it like:
Code:
while (end >= inputStr && *end == ' ') end--;
And just for efficiency you might want to avoid calling strlen() twice. You could create a size_t len and set that just before the memmove(). Then you could pass len to memmove() and use it in the calculation for your end pointer.
Also, sometimes it's helpful, if your function isn't going to return anything else, to return a pointer to the finished string. Sort of like strcpy() and the rest of the standard string functions do.
Looks good though!
My finished function, if I were to write it, would probably look like:
Code:
char *stripWhitespace (char *inputStr)
{
char *start, *end;
size_t len;
/* Strip leading whitespace */
start = inputStr;
while(*start == ' ') start++;
len = strlen(start);
memmove(inputStr, start, len + 1);
/* Strip trailing whitespace */
end = inputStr + len - 1;
while(end >= inputStr && *end == ' ') end--;
*(end + 1) = '\0';
return inputStr;
}