Returning the address of a "local block of storage" is always a bad idea. That memory is no longer yours to access once the function terminates.
Do you want to "remove spaces", or do you want to "make a copy without spaces"? Either way, it's not a good idea to have the "helper function" guess how much space might be needed for the copy. If the original is to be preserved, the caller should make a copy, then have the function "compact" the spaces out of the copy.
The following was written for another recent question. Notice that this version is able to remove all instances of several different characters in a single 'sweep' across the string.
#include <stdio.h>
#include <string.h>
// Define the function ahead of its use. It is its own prototype.
void remove_character( char *str, char *remove ) {
// copy characters, but only increment destination for "non-remove" characters.
for( size_t src = 0, dst = 0; ( str[dst] = str[src] ) != '\0'; src++ )
dst += (strchr( remove, str[dst] ) == NULL);
}
int main( void ) {
char s[] = "Thi!s is s!ome tex!t that we'!ll check for plagiarism";
char symbols[] = "!s"; // Stripping out '!' and 's'
puts( s ); // simpler
remove_character( s, symbols );
puts( s ); // simpler
return 0;
}
Thi!s is s!ome tex!t that we'!ll check for plagiarism
Thi i ome text that we'll check for plagiarim
Replace the "!s" with " " and this would achieve your objective.