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

What three simpler multiplications can you use to find 8*242
What do you call the procedure that helps you determine the volume of an irregularly shaped object, while using a graduated cylinder?
A hiker hikes in a straight line and maintains a constant velocity of +0.5 m/s. At time t=0.0 s, the hiker is 30 m from point A. What is the displacement from p
1/3 cup of flour makes 5 dinner rolls. How many cups of flour for 1 roll? and how much flower for 36 rolls?
What geographic factors influenced the development of the Atlantic slave trade
What might a French peasant have grumbled about in 1789?
A cube of ice, 12 cm on each side, is melted into a measuring cup. What is the volume of the liquid water?   I tried 12x12x12 but the answer is wrong
What do tolerance dissent and persecute have in common
did the assyrians cruelty help them or hinder them in ruling their empire?
which of the following measurement(s) has three significant figures?I.    0.0140II.   320III.  85,100A. I only.B. II and III only.C. I and III only.D. I, II, an