Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function str_search that will take 2 strings, pattern and text as parameters and will return the number of occurrences of pattern in text.

Write a function str_search that will take 2 strings, pattern and text as parameters and will return the number of occurrences of pattern in text. For example, if pattern is "ana" and text is "ana ate the banana", then the resulting value should be 3. Consider that matching is always case-sensitive. unsigned int str_search(const char *pattern, const char *text);

Must be in C++ and only include #incluse and or

Only can have the function. If you want to write a main to test it some test cases are

  • pattern = "ana", text = "ana ate the banana" ( should return 3) (Be careful with words like "banana" where the word contains the pattern multiple times, but shares letters with a previous occurrence)
  • pattern = "aa", text = "ana ate the banana"; (should return 0)
  • empty string, return 0
  • pattern = "ana ate the banana" , text = "ana ate the banana" (should return 1)
  • pattern = "na", text = "ana ate the banana" (should return 3)
  • pattern = " " (1 single space), text = "ana ate the banana" (should return 3)
  • pattern = "a a", text = "ana ate the banana" (should return 1)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions