brittneylouise679 brittneylouise679
  • 19-07-2017
  • Computers and Technology
contestada

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

Respuesta :

tonb
tonb tonb
  • 19-07-2017
Here's an attempt in C:

#include <string.h>

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();
}


Answer Link

Otras preguntas

Which on of th efollowing is not advantage of shifting to robotics?
Marathon runners: A. Only eat carbohydrates. B. Tend to have more slow-twitch muscle fibers. C. Are always very thin. D. Can one or two marathons a year
Write 0.0000004954 in scientific notation.
How do I answer this question?
Administration of chicken pox vaccine ( intramuscular) to patient 9 years old: no counseling required
What is is a simple definition of reduction?
Water enters the leaf through structure _____, whereas carbon dioxide enters the leaf through structures located within _____.
Which is an example of irony from The Great Gatsby? A. The "new" wealthy live in West Egg rather than East Egg. B. Tom must go into New York to meet with
consider the function f(x)=|x+3| and g(x) =-|x+3| the graph of g can be obtained from the graph of f by what transformation
When dissolved in water, some compounds separate into positively and negatively charged ions, which are called ____________ .