Friday, October 16, 2009

study notes

After I wrote assignment1, I felt that the io_display function written by Fardad is a really good study example, because when I first wrote displayflag, I wrote more than 30 lines of code to handle spaces and try to move the cursor around. After I walked though io_display function, I found Fardad used only two for loops with a few lines and did what my 30 lines did. So, I changed my displayflag function and called io_display inside.



This is my displayflag function final copy,

void io_displayflag(const char *format, int row, int col, int status) {

char format2[4];

strcpy (format2, format);

if (status == 0){

//display unchecked

format2[1] = ' ';

}

io_display(format2, row, col, 4);

io_move(row, col+1);

}


This is the display function written by Fardad,

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

io_move(row, col);

if(len <= 0){

io_putstr(str);

}

else{

int i;

for(i=0;i < len && str[i];i++){

io_putch(str[i]);

}

for(;i < len;i++){

io_putch(' ');

}

No comments:

Post a Comment