Hi, I need help with removing trailing and leading whitespace from a char array. Does anyone have any advice as to how I should do this. I can remove trailing whitespace by working backwards through a pointer (e.g. char *end = input + (strlen(input) - 1) and then do this:
Leading whitespace is harder because while I am able to work out how much of it there is by a simple loop I then need to move everything 'forwards' a few places, to effectively overwrite the whitespace (e.g. ' hello' would be moved two places to the left making 'hello').Code:while (*end && end == ' ') end--; *(end + 1) = '\0';
Can anyone help me with moving the whole string (up to a '\0') to the left by a few places?
Thanks for all of your help.