Thursday, October 1, 2009

OOP344 Challenge 3

For our third challenge, we had to reduce our display program even moreso. Down to one line as it were. This seemed pretty much impossible until I remembered 2 things. First that since "row" and "col" are passed by value, once we've positioned the cursor they aren't needed for anything and can be used as counters and second that we have conditional operators.

Don't let the wrap around and ridiculous size fool you. That's one, long, ridiculous For Loop.

void io_display(const char *str, int row, int col, int len){

for(io_move(row, col), (len <= 0) ? (col=len,(io_putstr(str))) : (col=0); col < len ;(str[col] ? io_putch(str[col]) : io_putch(' ')), col++);
}

No comments:

Post a Comment