Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C: 3. (10 points) Implement a function that identifies unique words in a stri

ID: 3716517 • Letter: I

Question

In C:

3. (10 points) Implement a function that identifies unique words in a string. This function should be case insensitive, and words can be separated with multiple spaces. For instance, f("It makes sense. He Makes tea!")It, makes, sense, He, tea!) The function must have the following properties: (a) Name: FindUniqueWords (b) Return type: An array of strings (.e., char**) allocated in the heap. Return NULL if for some reason the function cannot operate on the input (c) Argument 1 Input: A string. (d) Argument 2 - Output: A pointer to an integer indicating the number of found words.

Explanation / Answer

#include <stdio.h>
#include <string.h>
int main()
{
char inputstr[100];
char wordarray[10][10];
char newarray[10][10];
int i, j, k,count,flag,temp;
printf("Input a string :");
scanf("%[^ ]s", inputstr);
j=0;k=0;count=0;flag = 0;
for(i = 0; i <= (strlen(inputstr)); i++ ){
if(inputstr[i]==' '||inputstr[i]=='')
{
wordarray[j][k]='';
j++;
k=0;
}else{
wordarray[j][k] = inputstr[i];
k++;
}
}
for(i=0;i < j;i++){
for(k=0;k<count;k++){
if(strcmp(newarray[k], wordarray[i]) == 0){
break;
}
}
if(k==count){
strcpy(newarray[count],wordarray[i]);
count++;
}
}
printf("no of unique words in a sentence :");
printf(" %d ",count);
return 0;

}