Hello,
I've written a function which removes any punctuation from around a word. For Example:
Code:
input output
hello! hello
...foo foo
?they're... they're
My function looks like this:
Code:
void cleanWord(char **word) {
size_t len = strlen(*word);
int count = 0;
char *copy = *word;
char *temp = malloc(len);
if(temp == NULL) {
fprintf(stderr, "Memory Error\n");
exit(EXIT_FAILURE);
}
while(*copy) {
if(isalnum(*copy) || (!isalnum(*copy) && isalnum(*(copy-1)) && isalnum(*(copy+1)))) {
temp[count++] = *copy;
}
if(count == len) {
increaseBuffer(&temp, &len);
}
*copy++;
}
temp[count] = '\0';
*word = temp;
}
This is fine for a few words, but I need to process in excess of 29000 words, and my code seems to be lagging.
Could you help me make this more efficient please?
Thank you for your time.