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

help me, please!!!! i really can use it
the players passes or pass the ball.
PLEASE HELP. I'LL GIVE BRAINLIEST. Find the missing value to complete the square. So what is the value of the question mark that would make the equation true. x
1.làm tính nhân -3x. (x^2+7x-1/3)
The surface of an office desk has a perimeter of 12 feet and an area of 8 square feet. What are the dimensions of the desk? ____feet by ___feet HELP ME PLEASEE
The area of a rectangular hotel room is 260 square feet. The perimeter is 66 feet. What are the dimensions of the room? ____ feet by ____feet
Select the correct answer. The function Fx) = sin(x) is graphed on the domain (0,2*pie). Which statement is true about its leftmost point, where x =0 ? A. The p
anyone want to learn French with me​
Mary wanted to know if seeds needed water to start growing or if any kind of liquid would work. Mary set up several experiments to find out. She used radish see
Discuss the advantage and dis advantage of cell phones