July 2, 2015

Homework Help: programming

Posted by Ryan on Saturday, October 24, 2009 at 2:09am.

I really need help in this it makes me confuse.I should make a program to find a can somebody help me...
Write a function to recognize an pattern within another array. Your function should have the following prototype.

const int *find_pattern_in_int_array(const int *pattern, const int *array);

There are two parameters. The first one is pattern, which is an int pointer that points to the starting address of the pattern. The pattern ends with an int 0. The second parameter is the int array within which you need to locate the pattern. The array also ends with an int 0. If the pattern can be found in array, return the start address of last one within array. Otherwise you just return NULL. Note that you cannot access out of the array bound so you need to pay attention to the length of the pattern and the array, since the length of the array is not necessarily smaller than the length of the pattern.

You only need to write the function. The grading system will use various main programs to test the correctness of you function.
Please submit the function with #include<stdio.h>. DO NOT submit code with int main().

Sample Input/Output 1
Let's suppose you have pattern pointing to {8, 7, 0} and array pointing to {1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}.
In this case, you should return a pointer pointing to the second 8.

Sample Input/Output 2
pattern : {1, 2, 1, 0}
array : {1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}.
In this case, you should return NULL.

Answer this Question

First Name:
School Subject:

Related Questions

More Related Questions