I'm having some issues trying to remove all whitespace from a string (for example: "a b c x") using a method that takes a double pointer argument. I have solved it using single pointers and using strings in c++, but I wanted to get this working as well for curiosity's sake :)
This is what I've tried:
void remove_whitespace(char** s)
{
char **rd; // "read" pointer
char **wr; // "write" pointer
rd = wr = s; // initially, both read and write pointers point to beginning of string
while ( *rd != 0 ) // while not at end of string
{
while ( isspace( **rd ) ) // while rd points to a whitespace character
rd++; // advance rd
*wr++ = *rd++; // copy *rd to *wr, advance both pointers
}
*wr = 0; // terminate the result
printf("\nsquished: %s\n", s);
}
char**overchar*?char **for a single string? You don't reassignsso there's no need.printf("\nsquished: %s\n", *s);,"%s"expects achar*char** syou can havechar *rd, *wr; rd = wr = *s;.remove_whitespace()is called. Post a minimal reproducible example.