Ask Question

Assume s is a string of lower case characters.

Write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then your program should print

Number of times bob occurs is: 2

+5
Answers (1)
  1. 18 January, 10:23
    0
    Here's an attempt in C:

    #include

    int CountBob (const char * s)

    {

    int n = 0;

    while (s = strstr (s, "bob")) {

    n++;

    s++;

    }

    return n;

    }

    int main ()

    {

    char * s = "azcbobobegghakl";

    int n = CountBob (s);

    printf ("Number of times bob occurs is: %d", n);

    getchar ();

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs in s. For example, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers