Saturday, September 19, 2009

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

Here is my code for void io_display(const char* str, int row, int col, int len).

void io_display(const char* str, int row, int col, int len){
int i;
io_move(row, col);
len<=0 ? io_putstr(str) : 0;
for(i=0;i<len;i++){
str[i] ? io_putch(str[i]) : io_putch(' ');
}
}

First of all, I use io_move(row, col) to put the curse at somewhere I want, and then, I check whether len is less or equal than 0, if it's true, it will do io_putstr(str). However, I put a 0 there meaning do nothing. After that, I do a for loop in order to decide which I should print, str[i] or a space. I think it's shorter than Fardad's note.

No comments:

Post a Comment