Given a array string, I have to enter a word and find the occurrences of the word in the string, however I cannot enter the word for which I need to find the occurrence. I cannot use pointers as it hasn't been covered in the syllabus.
#include <stdio.h>
#include <strings.h>
int main()
{
    char sentence[100],word[20],temp[20];
    int i=0,j=0,occurrences=0;
    scanf("%[ ^\n]s",sentence);
    printf("Enter the word to be searched:\n");
    fgets(word,20,stdin);
    while(sentence[i]!='\0')
    {
        while(sentence[i]!=' '&&sentence[i]!='\0')
        {
            temp[j++]=sentence[i];
            i++;
        }
        temp[j]='\0';
        if((strcmp(temp,word))==0)
        occurrences++;
        if(sentence[i]==' ')
        j=0;
    }
    printf("Number of Occurrences of the word are %d",occurrences);
    return 0;
}
 
     
     
    