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

environmental movements that took place in world
26+6x is grater then or equal to 4(x+15) X >-17 x >17 X >15 X < 20.5
What is the definition of verbal irony?
Which was most highly valued by europeans intellectuals of the age of enlightenment?
What is 3. 2/15 simplified
adana adana adana merkez patlıyor herkez şekeri tutan o kulapaci son ses la bu cigaramiz enfes boş kafayla yaptın lan ses kes. copy copy please
What is the solution of the system of equations? y = –2x + 8 y = x – 4
What is the simplest form of a word called?
Many cultures died out as a result of the Bantu migrations because they were __________. A.starved to death B.exterminated in camps C.forced into other areas D.
What is a u-boat in world war one?