Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A (10 points): For this assignment, you will look for (that is, determine if the pattern is in the text) a specific pattern in

image text in transcribed

image text in transcribed

Part A (10 points): For this assignment, you will look for (that is, determine if the pattern is in the text) a specific pattern in a general text input. The text is read (one char at a time) and stored in a char array. If the pattern is recognized, then you will output a nice statement and indicate where in text the pattern starts (for example, position number 3). Remember, you will ONLY use pointer arithmetic and pointers for this assignment, if you use something of the form: array[index] you will lose credit. For example: Text: GCATCGCAGAGATATACAGTACG Pattern: GCAG A Match Has Been Found!!!! And It Starts At location 5 (starting from the left at 0). Now, what will your program do? First, you should assume you are searching for the pattern: "GCAG". You will code several functions as well as a main function. There should be one function that reads in some number of characters from the terminal and stores them into an array. You will use this function to store characters into your text array. You will also have a function that implements the recognizer. This function will have passed to it two char pointers, and returns an int which is the index to the location where the match starts or it returns -1 if it could not find a match (you should use this in your main function to print out the proper phrase "Yippee a match is found at location x" or "Too bad no match"). You will also create a function that is passed the char pointer of the TEXT and an int index where the match was found in the text, and of course the size of the text. A possible structure to your program is: #include #include int main() { char *text, *pattern; //pointers for the characters you will read char *p,*q, *r; // some pointer variables int n,m,x,y; // some integers int textSize; //ask the user how many characters are in the text that will be input int patternSize = 4; //this is fixed, since the pattern we are searching for is fixed as: GCAG char * getCharBlock(int textSize); //pass in the text size (from main) //this would fill in the "string" of chars for the passed in char pointer. YOU SHOULD //place a '\0' character at the end of the "string" (as an end of string sentinel) //this code MUST use pointer arithmetic and MALLOC to pass the char * back to main() int find Match(//what should be passed here?); //looks for a match, returns -1 for failure or an int which is the index to the location where the match starts. // the return values can be used to determine IF a match was found, and where. void printlt(char *ptr, int index, int size); //this is simple, just remember how pointer arithmetic works //prints a "string", starting from the pointer "index" //and any more functions for clarification of work done by the program. Remember, by designing and implementing // your code well, you simply need to call the functions nicely in main to find multiple locations of the pattern in the l/text. } In particular, you will use malloc, to store the char "string" text on the heap. Be very careful doing this, memory access here is somewhat tricky and you need to take care so start early on this

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions