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

In order to stimulate an effector in a toe, which pathway does a nerve impulse follow after it is initiated at a receptor?.
The horizontal component of the force acting on the crate is.
Which confederate state was the first to secede from the union?
Which version best uses a variety of sentence structures to enhance the flow and writing style of a story?
What is the key to natural selection Successful reproduction a Inherited traits b Genetic mutations c Genetic vartiations d Someone pls help me with this
solve pls brainliest
which process produces genetically different cells?
Isabelle is writing about a passage from the book Wonder by R. J. Palacio. “Go inside if you want,” Julian said. It was the first time he looked at me. I shrugg
what show’s theme was the first to be sung by its lead actors?
Ballio brought $29.00 to the state fair. He bought a burger, a souvenir, and a pass. The burger was 1 3 as much as the souvenir, and the souvenir cost 1 2 the c