Hey, my function traverses a 2D array of a sentence and a 2D array of words. The function then compares every position that word/s is in the sentence and replaces it with asterisks based on the length of the word. However, I want to store the new sentence in a new array and return that array. So far I've been able to do the comparison but applying the asterisks and creating the new array has been the trouble.
Code:
char *censor(char *message, char *list)
{
int sentencelen, wordlen,i,j,k,r;
//words are split
char** new_sentence = split_message(message, &sentencelen);
char** new_list = split_message(list, &wordlen);
//allocating memory for new array
char *result = malloc(sizeof(char)*strlen(message));
for(i=0;i<sentencelen;i++)
{
r=0;
for(j=0;j<wordlen;j++)
{
if(strcasecmp(new_list[j],new_sentence[i])==0)
{
r++;//increments when the word is found
}
//need help here
if(r==1)//if word is found
{
for(k=0;k<strlen(new_list[j]);k++)
{
//the lenght of the word replace with "*"
}
}
else
{
//attach the other words
}
}
}