Advertisements

Search results for short

Example:[1]

            Write a program to find the number of times that a given word(i.e. a short string) occurs in a sentence (i.e. a long string!).
          

            #include <stdio.h>
#include <string.h>
unsigned int search_word(char *,char *);
int main()
{
    char *s_str = "the";
    char *l_str = "the word searching for from these sentence is the.";
    unsigned int result;
    result = search_word(s_str,l_str);
    printf("Small string is found %d times in long string\n",result);
    return 0;
}
unsigned int search_word(char *s1,char *s2)
{
    int times = 0;
    int i = 0,j = 0,k = 0;
    int size = strlen(s1);
    printf("Size of small string \" %s \" is: %d\n",s1,size);
    while(s2[j] != '\0')
    {
        if(j >= (size - 1))
        {
            if(s2[j] == s1[size-1] && s2[j-1] == s1[size-2] && s2[j-2] == s1[size-3])
            {
                times = times + 1;
            }
        }
        j++;
    }
    return times;
}
          

 Search Links


 Popular C search MCQs


 Popular C search examples