I have written a method in C that removes characters from a string
char* removeChars(char input[], char remove[])
{
int src, dst = 0;
int size = strlen(input);
bool flags[128];
char output[18]; // <- This should be output[size]!
int i;
for(i=0; i<128; i++) {
flags[i] = false;
}
int j=0;
while(remove[j] != '\0') {
flags[remove[j]] = true;
j++;
}
for(src=0; src<size; src++) {
if(flags[input[src]] != true) {
output[dst++] = input[src];
}
}
return output;
}
One of the issues that I am having is that when I attempt to set the size of the output array using size (i.e. char output[size]), The output array appears to always have zero elements. It only seems to work when I specify a specific size (like 18). Should I be using strcpy or malloc instead? If so, how should it be done?