# Pset4 whodunit question

I'm trying to change the blue in clue.c. Right now, I made all the red into white, but i'm confused why my code doesn't change the remaining into black? Here's what i have. I'm trying to say, if it's not a white pixel, change it to black.

``````if(triple.rgbtRed ==  0xff){

triple.rgbtBlue = 0xff;
triple.rgbtGreen = 0xff;
}

if(triple.rgbtBlue != 0xff && triple.rgbtRed!= 0xff && triple.rgbtGreen != 0xff){
triple.rgbtBlue = 0x00;
triple.rgbtGreen = 0x00;
triple.rgbtRed = 0x00;
}
``````

Also, for the very beginning of the program, why do we need to remember the file names with char* infile = argv[1]; char* outfile = argv[2];. Can't we just use argv[1] and argv[2] in place of all of them?

• If you turn it into black, you'll just see a shadow. That's probably not ideal. Jul 2, 2016 at 15:13

``````if(triple.rgbtBlue != 0xff && triple.rgbtRed!= 0xff && triple.rgbtGreen != 0xff){
``````

This will be true only if all three triples are not 0xff. If any one of them is 0xff, then the test is false. That means that a pure red, green or blue pixel will not be turned to black. If you want to test for a pixel that is not white, you need to change the test to this:

if( !(triple.rgbtBlue == 0xff && triple.rgbtRed== 0xff && triple.rgbtGreen == 0xff) ){

When you're trying to test for a negative of a complex condition, it is simpler and better to just apply the not operator to the whole condition, as in `!(white)`. It's possible to do it by testing each individual condition, but it's a complex process to convert, and I don't recommend it for anyone that doesn't know how to fill out a truth table or hasn't had a course in digital logic.

As for using argv[x], yes, you can use them directly. Accessing the individual characters is the same as accessing an element in a 2 dimensional array. Assigning a different variable to them just makes it easier to access the data as a 1-dimensional array instead of 2d. It also makes for more descriptive var names to facilitate programming and debugging. Don't you think that infile is more meaningful than argv[1]? wouldn't it make it easier to understand what the code was doing?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)