dear Friends of CS50X,
I have been working on pset4, filter-less, reflection for several hours now.
I think my code does what it is supposed to do. Also, in my solution I tried to use the concepts taught in the lecture (using pointers array) to do the swap.
My code does compile, however, upon running the code with an actual image I get the following error: segmentation fault (core dumped)
what did I do wrong? I thought by declaring the pointer array int*inter[height][width] I was already allocating all the memory needed.
I'm trying to use the inter pointer array as a temporary array to swap the values and paste them back into the original image[height][width] array.
should I use malloc? I think this is an error due to memory issues, trying to touch memory I can't mess with
I have read posts from other CS50X students, and it seems there is more than one way to solve this problem. Some of you just don't use pointers or memory addresses at all, while others do use memory addresses.
I compiled the filters.c file and it compiles ok.
Any input is appreciated, the code bellow is only for rgbtRed.
thank you, al.
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
int *inter[height][width];
//inter=malloc(height*width);
for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
*inter[i][j]=image[i][j].rgbtRed;
}
for(int j=width;0<j;j--)
{
image[i][width-j].rgbtRed=*inter[i][j];
}
}
}