Finding integer sub array into full array please help

void findsubstring(int arr[],int substring[],int arrlength,int substringlength)
{
int i,j;
for(i=0;i<arrlength-substringlength+1;i++)
{
for(j=0;j<arrlength;j++)
{
if(arr[i+j]!=substring[j])
{
break;
}
if(j==substringlength)
{
return i;
}
}
}
return -1;
}
@Codman, please put your code in code tags so that we can see what it does without having to download and reformat it. It also helps to have complete-ish code that we can compile and run.

You don't actually state what your problem is. However, FWIW, you are trying to return something from a void function, which is a contradiction, since a void function returns nothing. Probably the signature of your procedure should be
int findsubstring(int arr[],int substring[],int arrlength,int substringlength)

I imagine the limit on j is also wrong; maybe
for(j=0;j<substringlength;j++)
Last edited on
Topic archived. No new replies allowed.