furthest right black pixel

I have a black and white image, and I'm only interested in finding the x-position of the furthest right black pixel, but I'm not sure how to proceed. Any help would be appreciated. Oh, and I'm using CImg and VC2008.

Alright, I feel pretty dumb since I didn't realize for loops could be iterated backwards. Anyways, here is what I have now.

int right_edge(CImg<unsigned char> bw)
    int width = bw.width();
    int height = bw.height();
    for( int i=height; i>0; i-- ){
        for( int j=width; j>0; j-- ){
            if( bw[j,i] == (0,0,0) )     //I know this line is the problem
                cout << j << endl;
            return 0;

The code compiles, but doesn't output as expected. I know the line with the if statement is formatted wrong. I've tried a whole bunch of Google results, but nothing has seemed to work (ie I'm probably messing up)


Simple psuedocode algorithm:

for each column of pixels (starting from the rightmost column, moving left)
    for each row
        if this pixel is black
            return x coordinate of column

I am deliberately leaving specifics out, as this seems to be a homework question and no effort has been shown on your part. But, this should be enough to get you started.

Need Your Help

no line found exception

java java.util.scanner

Help again guys, why do I always get this kind of error when using scanner, even though I'm sure that the file exists.

Python OO: how to stop procedure flow in an entire class with `return` statement?

python oop class flow

This is a beginner OO Python question. I wish there was a stackoverflow for beginners were I could ask this without get negative votes. So, here we go.