Below I have given my attempt to solve this question.
int count(char s[], char c[]) //s[]-->input text and c[]-->word to be searched
{
int i = 0, wcount = 0;
while (s[i] != '\0') {
char temp[10];
int j = i, k = 0;
while (s[j] != ' ') {
temp[k] = s[j];
j++;
k++;
}
if (strcmp(temp, c) == 0)
wcount++;
i += k;
}
return wcount; //word count
}
What I am trying to do is to browse each word and compare it with c[]
. I am storing a currently browsed word in temp array. In the output it takes input but does not show any output sometimes stops causing error. I could not figure out the problem.
Aucun commentaire:
Enregistrer un commentaire