Question
Task -> Implement the function specifications, i.e. the prototypes. Search a sentence for the occurrence of a pattern. Report the position where the pattern occurs.
Task -> Implement the function specifications, i.e. the prototypes.
Search a sentence for the occurrence of a pattern. Report the position where the pattern occurs. It might not occur, occur only once, or could occur many times. Find all the matches and output their position in the sentence. The position starts at index=0 at the beginning of the sentence.
See the sample test case for input and output formats.
Template
//System Libraries Here #include
//User Libraries Here
//Global Constants Only, No Global Variables //PI, e, Gravity, or conversions
//Function Prototypes Begins Here //srch1 utility function Input->start position, Output->position found or not //srch1 is a simple linear search function, repeat in srchAll till all found //srch1 Input->sentence, pattern, start position Output-> position found //Remember arrays start at index/position 0 //srchAll Input->sentence, pattern Output->position array int srch1(const char [],const char [],int);//Search for 1 occurrence void srchAll(const char [],const char [],int []);//Search for all occurrences void print(const char []);//Print the character arrays void print(const int []); //Print the array of indexes where the pattern found
//Program Execution Begins Here int main(int argc, char** argv) { //Declare all Variables Here const int LINE=81; //Size of sentence or pattern to find char sntnce[LINE],pattern[LINE]; //80 + null terminator int match[LINE]; //Index array where pattern was found //Input a sentence and a pattern to match cout<<"Match a pattern in a sentence."< C++ Please
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started