...
| Code Block | ||
|---|---|---|
| ||
void remove_spaces(char const *str, size_t slen) {
char *p = (char*)str;
size_t i;
for (i = 0; i < slen && str[i]; i++) {
if (str[i] != ' ') *p++ = str[i];
}
*p = '\0';
}
|
/
Compliant Solution
In this compliant solution the function remove_spaces() is passed a non-const char pointer. The calling function must ensure that the null-terminated byte string passed to the function is not const by making a copy of the string or by other means.
...