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

Which inequality represents this sentence? Five plus four is less than ten plus two. (A) 5+4<10+2 (B) 5+4>10+2 (C) 10+2<5+4 (D) 5+4≤10+2
What does crucial aspect mean?
The Roman who married the queen of Egypt and later committed suicide was: Marc Antony Julius Caesar Brutus Tiberius Gracchus
During winter, which winds deliver cold air that enters North Carolina? (WHY) A. northeast trade winds B. Southeast trade winds C. prevailing westerlies D. pola
Data on the blood cholesterol levels of 6 rats give mean = 85, s= 12. A 95% confidence interval for the mean blood cholesterol of rats under this condition is a
If y = x3 - 3 , find the value of y when x = -2
When you solve a problem involving money, what can a negative answer represent?
Comment fo vous conjuguer er verbes?
based on the miranda warning that is evolved from the supreme court case miranda v. arizona,what rights is a person entitled to when she is arrested? give examp
Which option is the most accurate description of speed? 1. The ball rolled down the hill in five seconds to reach the marker. 2. The ball rolled down the