Sunday, September 27, 2009

challenge 3 --- void io_display(const char* str, int row, int col, int len)

This is my code for challenge 3 which makes the io_display function shorter. Here is my code:
void io_display(const char* str, int row, int col, int len){
for(io_move(row,col), len<=0 ? io_putstr(str):0;0<len;*str?io_putch(*(str++)):io_putch(' '), len--);
}

I put io_move(row, col) in the initial part, and also in the initial part, I check if "len" is less or equal than 0. And I only put 0<len in the condition part, so I check the str at the last. At the very last, I put len-- to make the for loop work. I think it's shorter than my previous code because it's only ONE line.

No comments:

Post a Comment