Thank you guys very much for your contributions!
Though, I dont't think I should replace the outermost loop's condition
for (i=0; i < LineLength; i++)
with
for (i=0; i < LineLength - FragmentLength; i++)
Please consider the following example:
LineLength = 17
FragmentLength = 3
Suppose the fragment I am looking for begins at element #14, so its last element is in element #16 of 'line'. However, you suggest I should only read up to 17-3, that is 14. I get an error.
Also, you are saying that this test isn't necessary:
|
if (line[i] == fragment[0])
|
When I omit this test, I keep getting errors when I try to find a 'fragment' that is towards/at the end of 'line'. Why?
My code handles this cases correct. I inserted this test because I only wanted the program to descend into the subsequent loops if this condition was met. I thought the program would be faster like that.
And, if FragmentLength is 0, well, the "fragment could not be found in line."
Can anyone help?