Posted by Ryan on Saturday, October 24, 2009 at 2:09am.
The confusion may be coming from trying to take in too many things at once.
At root, all this is asking is for you to write a function to find a sequence like {8, 7} in a sequence like (1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1} - which is essentially the same process as finding "the" in "I thought the problem was harder than it was."
I'd focus on finding the sequence, get the general approach clear in my head, and then worry about the details and the bureaucracy.
How do you find a sequence - pattern - within another sequence - array? In general, you can:
1. Look along array, looking for the first element of pattern (loop through array looking for 8)
2. When you've found the start of pattern in array, compare subsequent elements in both to see if they are the same.
3. Keep doing this until you've reached the end of array. The last one you found is the answer, or NULL if none found.
It's the same logic that's used in strstr(), for example, to find "wo" in "hello, world". They're just using arrays of integers here, which are less familiar than arrays of chars, but really very little else is different.
Don't get hung up on the const. It just means that the values specified can be read, but not changed.
You can't include your main() in your project, but if I were doing this, the first thing I'd do would be to write that main() using the first example - something like
const int *find_pattern_in_int_array(const int *pattern, const int *array);
int main()
{
const int pattern[] = {8, 7, 0};
const int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int *return_value;
return_value = find_pattern_in_int_array(pattern, array);
}
to provide me a testbed for the function.
Does this help any? If you want to provide some code or ask a specific question, I'm sure I or somebody here will be happy to have a look at it.
Related Questions
PROGRAMMING - PLS, I NEED TO BE GUIDED ON HOW TO WRITE A SIMPLE PROGRAM IN BASIC...
Programming Logic - I need to create a program that has (at least) two variables...
Programming Logic - I need to create a program that has (at least) two variables...
c programming - Plz give me some idea that how can i do this program. Write a ...
Programming - I need your help to write a program using visual basic 2010 for ...
Programming - Write a program that would calculate and display the results for ...
Programming - Here is the question that I need help to write the code for the ...
programming - I have just started C programming after a semester of Java. I am ...
programming - 2-5 Grade Determination is says " Write a program that will ...
c programming - Write a program that uses a 20x20 board, initialised to a given ...
For Further Reading