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 is the value of x in the equation 3x-4y=65 when y=4
solve cot [tex]cot5pi/12[/tex]5pi/12
Carlos has 7 1/2 acres of farmland. He uses 1/3 of the acres to graze animals and 1/5 of the acres to grow vegetables . How many acres does Carlos use for graz
Verbatim means a. elegance in talk. b. incoherence c. pertaining to the back. d. quoted word for word
What caused the United States to break its neutrality and enter World War I? a.It had signed a treaty of alliance with England in 1902. b.The Germans were sinki
What is the value of the written problem (-9)-(-1)
One who specializes in the treatment of infants is a a. psychiatrist. b. dermatologist. c. gynecologist. d. pediatrician.
PLZ HELP FAST ASAP THANKS GUYS!!!!!!!!!!!!! ALSO WILL GIVE BRANLIEST Use a proportion to find the missing side length, xx . Enter your answer in the box. Two
Pero compré (estas / esta) camisa azul.
What is the molar mass of oxygen, O2? (Round to four significant figures only.)