Sunday, November 29, 2009

Use Real Syntax of Main to write something into a file

#include
#include

int main(int argc, char* argv[]){
FILE* fp;
char ch;
if(argc!=2){
printf("you forgot to enter the filenname.\n");
exit(1);
}
if((fp=fopen(argv[1],"w"))==NULL){
printf("cannot open file.\n");
exit(1);
}
do{
ch=getchar();
putc(ch,fp);
}while(ch!='$');
fclose(fp);
return 0;
}
After you compile it, you can run it on command prompt. And you can type in anything except you enter "$" and press enter key.

IO_Menu and IO_CheckList

In Fardad's IO_Menu and IO_CheckList, when you reach the last item in the vertical menu, radio, or checkbox and you press down key, it does nothing and stops there. But it's supposed to go back to the first item. And the up key has the same problem. So I change some codes there to fix the problem.
For example in Vertical Menu:
case DOWN_KEY:
if(_dir == Vertical){
if(x < _len-1){
x++;
}
else {
x=0;
}
}
else{
done = true;
}
break;
case UP_KEY:
if(_dir == Vertical){
if(x > 0){
x--;
}
else {
x=_len-1;
}
}
Then, do the same thing to IO_CheckList.

Monday, November 2, 2009

Copy constructor and assignment operator for DsStack class

1. copy constructor
1.1 Stack::Stack(const DString data){
this->top=(SNode*)0;
Push(data);
}
1.2 Stack::Stack(const Stack& t){
this->top=(SNode*)0;
*this = t;
}

2. assignment operator
Stack& Stack::operator=(const Stack& t){
while(!IsEmpty()){
Pop();
}
SNode* temp=t.top;
while(temp){
Push(temp->data);
temp=temp->next;
}
delete temp;
SNode* tem=this->top;
this->top=(SNode*)0;
while(tem){
Push(tem->data);
tem=tem->next;
}
delete tem;
return *this;
}

Thursday, October 29, 2009

IRC classes

We took our IRC class this Tuesday, and got a lot of information about how to start our project. It’s really a good idea to talk about project on-line, because when fardad said something, we could do it on our computer immediately. Actually, it’s the same to lab class, but unfortunately, we didn’t have lab class. In addition, we can have our meeting a little bit later than regular schedule, our team (BINGO) will meet on IRC at 9:00pm on both Tuesday and Friday, in order to ensure everyone can join our meeting. And also, we got a lot of extra time to prepare for the meeting, such as installed SVN. However, the only imperfection is that wasting lots of time on typing. Anyway, I really enjoy IRC class.

Saturday, October 10, 2009

Problem on as1tester.c, Maybe BUG

I just tested my code by using as1tester.c, but I found some problem with test 9.23. It said "Test 9.23: io_edit() Escape when IsTextEditor = 0, hit HOME key, then 'a', 'b', 'c' and then ESCAPE to test!", but it would be always failed because it required everything equals default value, I mean, nothing was allowed to change. So if you hit HOME KEY and insert three letters, that's impossible to pass the test. Therefore, I think there is a bug here.

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.

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.