argc is the number of items or arguments on the command line that were used to write the program.
argv[0] is the name of the program
argv[1] is the first command line parameter
argv[argc-1] is the last command line parameter
argv[argc] is always a null pointer
so, if we have " $ RemOrder Orders.bin NewSOrders.bin 20 " in our command line.
argc == 4
argv[0] == RemOrder ( name of program which parameter to run )
argv[1] == Orders.bin
argv[2] == NewSOrders.bin
argv[3] == 20
Monday, November 30, 2009
Friday, November 27, 2009
Reading old test
As I read farad's old test, I learned new thing about destructor of inherited class.For e.g if we have :
handle *h[4] = {new boo(10), new bee(), new boo(4.2),new bee()};
so, we have an array of 4 element which points to class handle.
each element is included different class which are inherited of class handle.
if we say
for(i=0;i<4;i++){delete h[i];}
In this case,only destructor of class handle will be called because h is pointing to class handle,except if we declare handle's destructor as a virtual.
If we say virtual in destructor of parent,child will be destroyed then parent.
handle *h[4] = {new boo
so, we have an array of 4 element which points to class handle.
each element is included different class which are inherited of class handle.
if we say
for(i=0;i<4;i++){delete h[i];}
In this case,only destructor of class handle will be called because h is pointing to class handle,except if we declare handle's destructor as a virtual.
If we say virtual in destructor of parent,child will be destroyed then parent.
Wednesday, November 18, 2009
Assignment 2
I was supposed to write IO_Menu class but fardad almost finished it in class.
I just read step by step what fardad defines menu as a derived class of io_field
and io_frame. IO_Menu is derived from IO_Frame in order to draw frame for vertical
menu and also is derived from io_field to consider row and col field in frame. we can move between menu items by page up,down key for vertical menu and right, left keys for horizontal menu. By space key , menu item would be selected and the previous selected menu item would be deselected.
Now I am going to focus on io_form with lujbo. If we finish io_form , io_field and io_label, then project can pass the first test.
I was supposed to write IO_Menu class but fardad almost finished it in class.
I just read step by step what fardad defines menu as a derived class of io_field
and io_frame. IO_Menu is derived from IO_Frame in order to draw frame for vertical
menu and also is derived from io_field to consider row and col field in frame. we can move between menu items by page up,down key for vertical menu and right, left keys for horizontal menu. By space key , menu item would be selected and the previous selected menu item would be deselected.
Now I am going to focus on io_form with lujbo. If we finish io_form , io_field and io_label, then project can pass the first test.
Sunday, November 8, 2009
Copy files
The following code, copy source file to destination file.
First, It opens source file for "reading" and also opens destination file for writing.If destination file doesn't exist, it will creates it.Then it starts to read from source file line by line ,simultaneously it writes to destination file until reaches to no data or end of source file.
#include
#define TEXT_SIZE 1024+1
int main(void)
{
FILE* fp_in;
FILE* fp_out;
char TEXT[TEXT_SIZE];
int Byte;
fp_in=fopen("test1.txt","r");
if (fp_in==NULL)
{
printf("Error:can not open source file\n");
}
else
{
fp_out=fopen("test3.txt","w");
while(fscanf(fp_in,"%[^\n]\n",TEXT)==1)
{
fprintf(fp_out,"%s\n",TEXT);
}
fclose(fp_in);
fclose(fp_out);
}
printf("done!\n");
return 0;
}
First, It opens source file for "reading" and also opens destination file for writing.If destination file doesn't exist, it will creates it.Then it starts to read from source file line by line ,simultaneously it writes to destination file until reaches to no data or end of source file.
#include
#define TEXT_SIZE 1024+1
int main(void)
{
FILE* fp_in;
FILE* fp_out;
char TEXT[TEXT_SIZE];
int Byte;
fp_in=fopen("test1.txt","r");
if (fp_in==NULL)
{
printf("Error:can not open source file\n");
}
else
{
fp_out=fopen("test3.txt","w");
while(fscanf(fp_in,"%[^\n]\n",TEXT)==1)
{
fprintf(fp_out,"%s\n",TEXT);
}
fclose(fp_in);
fclose(fp_out);
}
printf("done!\n");
return 0;
}
Saturday, October 31, 2009
IRC meeting on Study Week
In this meeting I learned how to check out from SVN and work on shared documents then add my new files and finally commit ,so everyone in my group can see my work.If everyone edits the shared area at the same time, I can receive their changes through update.It is better to have a backup of my files in order not to lose any files by mistake.every changes in SVN creates a number as a revision , so it shows how many times it has been changed. Although by SVN checkout -r revision number we can access to our older files, but it is better to have a backup.
Until now, I know everyone has to write one class by dividing each class to IO_XXX.h header file and IO_XXX.cpp description file. We can compile and test our class in our individual main. everyone has its own separate main and just we need to call our specific main and test it.
In this meeting I learned how to check out from SVN and work on shared documents then add my new files and finally commit ,so everyone in my group can see my work.If everyone edits the shared area at the same time, I can receive their changes through update.It is better to have a backup of my files in order not to lose any files by mistake.every changes in SVN creates a number as a revision , so it shows how many times it has been changed. Although by SVN checkout -r revision number we can access to our older files, but it is better to have a backup.
Until now, I know everyone has to write one class by dividing each class to IO_XXX.h header file and IO_XXX.cpp description file. We can compile and test our class in our individual main. everyone has its own separate main and just we need to call our specific main and test it.
Thursday, September 17, 2009
the following function gets an integer value and converts it to a string ("strint") without using any library functions: Although it is long but it works.
void GetInt(char *strint, int val)
{
char *str;
int length=0;
int rev = 0,i=0,num;
/* get the length of int number */
num=val;
do{
i++;
num=num/10;
}
while(num==0);
/* allocate memory */
str=new char[i];
strint=new char[i];
/* convert it to character , */
while (val > 0)
{
int a = val % 10;
str[length++] = a | '0';
val /= 10;
}
str[length]='\0';
length--;
while (length >= 0)
{
strint[rev++] = str[length--];
}
strint[rev] = '\0';
}
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;i++)
{
str[i]? io_putch(str[i]) :io_putch(' ');
}
}
}
void GetInt(char *strint, int val)
{
char *str;
int length=0;
int rev = 0,i=0,num;
/* get the length of int number */
num=val;
do{
i++;
num=num/10;
}
while(num==0);
/* allocate memory */
str=new char[i];
strint=new char[i];
/* convert it to character , */
while (val > 0)
{
int a = val % 10;
str[length++] = a | '0';
val /= 10;
}
str[length]='\0';
length--;
while (length >= 0)
{
strint[rev++] = str[length--];
}
strint[rev] = '\0';
}
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;i++)
{
str[i]? io_putch(str[i]) :io_putch(' ');
}
}
}
Subscribe to:
Posts (Atom)