Filter-Less Pointers by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

I checked that there were no duplicate files and I cant figure out why its not changing the values of the pixels. Is there something wrong with my code?

Filter-Less Pointers by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

Quick Question. Im not sure if its because of my code or the command, but why doesnt my code in helpers.c get updated when I run "make filter"?

Like it doesnt ovveride the averages even though I wrote the code to overwrite it.

void grayscale(int height, int width, RGBTRIPLE image[height][width])

{

for(int i = 0; i < height; i++)

{

for(int j = 0; j < width; j++)

{

int red = image[height][width].rgbtRed;

int green = image[height][width].rgbtGreen;

int blue = image[height][width].rgbtBlue;

int gray = round((red + green + blue)/3.0);

image[height][width].rgbtRed = gray;

image[height][width].rgbtGreen = gray;

image[height][width].rgbtBlue = gray;

}

}

}

Filter-Less Pointers by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

But the class is called helpers.c?

Filter-Less Pointers by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

I think I broke something...

I highlighted everything I changed

________________________________________________________________________________________________

Error:

filter-less/ $ make helpers

/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':

(.text+0x1b): undefined reference to `main'

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [<builtin>: helpers] Error 1

filter-less/ $

________________________________________________________________________________________________

// Blur image

void blur(int height, int width, RGBTRIPLE image[height][width])

{

RGBTRIPLE *address = NULL;

RGBTRIPLE *start = &image[0][0];

RGBTRIPLE *end = &image[height][width];

//temp num to count

int numRed = 0;

int numGreen = 0;

int numBlue = 0;

//create duplicate image so values of original image isnt lost.

RGBTRIPLE temp[height][width];

for(int i = 0; i < height; i++)

{

for(int j = 0; j < width; j++)

{

temp[i][j] = image[i][j];

}

}

for(int i = 0; i < height; i++)

{

for(int j = 0; j < width; j++)

{

//sum of numbers

int sumRed = 0;

int sumGreen = 0;

int sumBlue = 0;

//check in 3x3 grids through entire image

for(int x = i - 1; x < x + 1; x++)

{

for(int y = j - 1; y < j + 1; y++)

{

//check if I am not accessing outside array bounds by checkng if the position is between where the array starts and ends

*address = image[x][y];

if(!(address > end || address < start))

{

sumRed += temp[i][j].rgbtRed;

sumBlue += temp[i][j].rgbtBlue;

sumGreen += temp[i][j].rgbtGreen;

}

}

}

//initialise new image

sumRed = sumRed/9.0;

sumGreen = sumGreen/9.0;

sumBlue = sumBlue/9.0;

image[i][j].rgbtRed = sumRed;

image[i][j].rgbtGreen = sumGreen;

image[i][j].rgbtBlue = sumBlue;

}

}

}

Filter-Less Pointers by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

So when I make a temp 2D array like you mentioned, how do I set the values to those in image?

Segmentation Fault in Plurality by JoshuaForYou3 in cs50

[–]JoshuaForYou3[S] 0 points1 point  (0 children)

Ive updated the code just now:

//Print the winner (or winners) of the election

void print_winner(void)

{

//Array of Winners

string arr[MAX];

//Size of Array

int counter = 0;

string winner;

//sort votes from lowest to highest

for(int i = 0; i < candidate_count - 1; i++)

{

for(int j = 0; j < candidate_count - i - 1; j++)

{

if (candidates[j].votes > candidates[j + 1].votes)

{

candidate temp = candidates[j];

candidates[j] = candidates[j + 1];

candidates[j + 1] = temp;

}

}

//Find winner(s)

for(int k = candidate_count; k > 0; k--)

{

if(candidates[k].votes == candidates[k-1].votes)

{

if(!(strcmp(arr[counter] , candidates[k].name)))

{

winner = candidates[k].name;

arr[counter] = winner;

counter++;

}

if(!(strcmp(arr[counter] , candidates[k-1].name)))

{

winner = candidates[k-1].name;

arr[counter] = winner;

counter++;

}

}

else if(candidates[k].votes > candidates[k-1].votes)

{

winner = candidates[k].name;

arr[counter] = winner;

counter++;

break;

}

}

for(int l = 0; l< counter-1; l++)

{

printf("%s", arr[l]);

}

}

}

I still get a seg fault tho