Saturday, October 17, 2009

OOP344 assignment 1 IsTextEditor=1 left,right key problem

Assignment 1 Link
IsTextEditor=1,
leftkey and right key:
case LEFT_KEY:
if ((*offset)>4){
(*offset)-=4;
(*curpos)+=4;
}else{
(*curpos)+=(*offset);
(*offset)=0;
done=1;
}
break;
case RIGHT_KEY:
if(io_len(str)-*offset-fieldlen>4{
*offset = *offset +4;
*curpos=*curpos-4;
}else if(io_len(str)-*offset-fieldlen>0){
*offset=io_len(str)-fieldlen;
*curpos=*curpos-io_len(str)+*offset+fieldlen;
done=1;
}
break;
it can't pass test9.20
how the left key and right key works. for example, if I click left key, what's the *curpos and *offset should be? I'm confusing about this.
If I just put
case RIGHT_KEY:
case LEFT_KEY:
done=1;
break;
it can pass test9.20. But I think this is not the correct answer.
Anybody has some idea about this? I'm already two day behind the due day.
Thanks.

6 comments:

  1. You should have 2 different cases for when isTextEditor is 0 and when isTextEditor is 1.

    When it is enabled, you should not change the "look" of the screen. So, when it gets to the end of the screen you should end function: set done=1

    ReplyDelete
  2. Thanks for the reply.I have another isTextEditor=0, that part works fine. Only the isTextEditor=1 part problem.
    I think when isTextEditor=1, one click of left key = move screen to the left 4 character, if not reach the beginning of the string, it will stay in the loop. if it reach the beginning of the string, then done=1, exit the loop.
    Is my thinking right?
    So the testing is ask me to left key 4 times, it means move to left 16 characters. If it is not the beginning of the string, it will wait for key enter.

    ReplyDelete
  3. if the screen can't move, so left key = move the string to the right 4 character? if *offset still >0, wait for key enter, otherwise exit loop?

    ReplyDelete
  4. The testing is asking you to move left 4 times. You will exit the loop on the 4th because that is when the cursor is at the beginning of the screen, not the string.

    This applies to both LEFT and RIGHT keys.

    Ex: [BCDEFG] showing on the screen, you cannot go past B or G so exit when you get there.

    ReplyDelete
  5. Thanks for the reply.
    Ex. [BCDEFG], *curpos=3, if left key only move 1 character each time, so after 2 times, the third time should exit. The left and right key only change the *curpos, right? I'm going to test it.

    ReplyDelete
  6. It works.
    I past the test9.20.
    This wiki + RSS really helped me. I can't believe it. It's interesting.

    ReplyDelete