Two problems:
for (i=0;(n+m-1);i++)
You're not limiting i
to anything, so the loop doesn't exit when you reach the end of your arrays; it just keeps incrementing i
until you hit memory you don't own, at which point you get the segfault. Since conv
only goes to m
or n
, I think you meant to write
for (i = 0; i < n; i++)
Secondly, you declared conv
as an Nx1 array, meaning the only legal index in the second dimension may be 0, so the lines
conv[i][1] = 0;
and
conv[i][1]=conv[i][1]+(aux1[j]*aux2[i-j+1]);
should be
conv[i][0] = 0;
and
conv[i][0]=conv[i][0]+(aux1[j]*aux2[i-j+1]);
Not sure why you declared an Nx1 array (seems you could have just declared conv
with one dimension), but I may be missing something obvious.
Note that your x
and h
arrays initially contain random values.