- strstr
- strtok
- atoi
Monday, December 24, 2007
Technical Books List
- Thinking in C++ I&II
- C++ Primer
- Effective C++
- More Effective C++
- Effective STL
- C++ TR1
- Algorithms
- Data Structure
- ...
Sunday, December 16, 2007
IT interview Questions & Answers
- what are you expectations from your job?
- 24-point game, how to verify whether these four numbers can be sum as 24? how many combinations?
Thursday, December 13, 2007
Organizing the world's information, socially
Director of Google China R&D gave a talk here this morning. It's a very good presentation, and even I, a bad English learner, understand almost all his points without the ppt slides.
Some points are representative:
(1) Social network, focus on the relationship between users on internet
(2) mobile application, due to hugh amount of mobile users
(3) for R&D, the most important thing is data. Without the data, or with noising data, we can do nothing. That's why they pay attention on Facebook, etc
Some points are representative:
(1) Social network, focus on the relationship between users on internet
(2) mobile application, due to hugh amount of mobile users
(3) for R&D, the most important thing is data. Without the data, or with noising data, we can do nothing. That's why they pay attention on Facebook, etc
Thursday, November 29, 2007
How to determine the size of an array
- sizeof a/sizeof *a (btw, sizeof is an operator instead of a function)
Monday, November 26, 2007
Some problems...
// there are two temporary objects to be de-constructed
1. class Person
{
static int num;
public:
Person() { num++; }
~Person() { num--; Print(); }
void Print() { cout<<"The person num is: "<< num << endl; }
};
int Person::num=0;
Person foo(Person p){ p.Print(); return p;}
void main()
{
Person p1;
p1.Print();
Person p2=foo(p1);
p2.Print();
return;
}
// when resize an array, delete the old array before assign a new one
2. void test(int *&array)
{
int *var = new int[20]; for (int i=0;i<10;i++)
{ var[i]=array[i]+10; }
for (int i=10;i<20;i++) var[i]= i * 3;
if(array) delete[] array; array=var;
}
int main()
{
int *var = new int[10];
for (int i=0;i<10;i++) var[i]=i;
test(var);
for (int i=0;i<20;i++) cout << var[i] << "\n";
delete [] var;
}
1. class Person
{
static int num;
public:
Person() { num++; }
~Person() { num--; Print(); }
void Print() { cout<<"The person num is: "<< num << endl; }
};
int Person::num=0;
Person foo(Person p){ p.Print(); return p;}
void main()
{
Person p1;
p1.Print();
Person p2=foo(p1);
p2.Print();
return;
}
// when resize an array, delete the old array before assign a new one
2. void test(int *&array)
{
int *var = new int[20]; for (int i=0;i<10;i++)
{ var[i]=array[i]+10; }
for (int i=10;i<20;i++) var[i]= i * 3;
if(array) delete[] array; array=var;
}
int main()
{
int *var = new int[10];
for (int i=0;i<10;i++) var[i]=i;
test(var);
for (int i=0;i<20;i++) cout << var[i] << "\n";
delete [] var;
}
Sunday, November 25, 2007
Notes on Programming Style
1. Less use of C/C++ standard library functions, for easy transplantation.
2.
2.
Notes on Data Type
1. void
2. null
3. bool: true/false
------------------------
4. char - 8 bit(1 byte); int - 2 bytes; float; double;
max/min number are defined in limits.h/float.h
short int, int, long int, float, double, long double
signed/unsigned(signed--forced to use a sign)
2e-2: the base e means 10
2. null
3. bool: true/false
------------------------
4. char - 8 bit(1 byte); int - 2 bytes; float; double;
max/min number are defined in limits.h/float.h
short int, int, long int, float, double, long double
signed/unsigned(signed--forced to use a sign)
2e-2: the base e means 10
Saturday, November 24, 2007
Notes on reading "Thinking in C++"
I am reading the book Thinking in C++ these days. I will write down some important points in this post during my reading.
1. Difference on overloading and overriding:
Overriding - same methods with same arguments and same return types associated in a class and its subclass
Overloading - same methods with different arguments, may or may not be same return type written in the same class itself
-------------------------------------
Example for overriding
Class A { Virtual void hi(int a) { }}
Class B: public A{ public overrid void hi(int a){ }}
Example for overloading
Class A {a(){} a(int a){}}
-------------------------------------
2. two ways to re-use the codes: compoition and inheritance
3. Three points on OOP: abstract data type, inheritance, polymorphism
4. Precedure of compilation: (1) pre-processing (2) compilation: (a) syntax analysis->tree structure (b) code generator->assemble code/machine code (get .obj) (3) linker. Some points: global optimizer, peephole optimizer, static type checking, dynamic type checking
5. All C++ library are in name space of std
6.
1. Difference on overloading and overriding:
Overriding - same methods with same arguments and same return types associated in a class and its subclass
Overloading - same methods with different arguments, may or may not be same return type written in the same class itself
-------------------------------------
Example for overriding
Class A { Virtual void hi(int a) { }}
Class B: public A{ public overrid void hi(int a){ }}
Example for overloading
Class A {a(){} a(int a){}}
-------------------------------------
2. two ways to re-use the codes: compoition and inheritance
3. Three points on OOP: abstract data type, inheritance, polymorphism
4. Precedure of compilation: (1) pre-processing (2) compilation: (a) syntax analysis->tree structure (b) code generator->assemble code/machine code (get .obj) (3) linker. Some points: global optimizer, peephole optimizer, static type checking, dynamic type checking
5. All C++ library are in name space of std
6.
Sunday, November 11, 2007
Some notes on C/C++
1. you can create a file with ofstream in a c/cpp programe, but you cannot create a directory such way
Problems to be thinking
1. why mysql comes out a problem with "release mode", say not start with "/"
2. why when there is directory, there may be problem with compling
2. why when there is directory, there may be problem with compling
Saturday, November 10, 2007
Some notes on MySQL
1. how to check whether a field is NULL?
First, NULL in MySQL is not a value, it is a condition. So if you try and write something "= NULL" you'll get an empty set rather than the results you're looking for. Try "IS NULL" instead. For example, mysql> select * from demo_people left join demo_property on demo_people.pid = demo_property.pid where spid is NULL;
2. becaulful with this code:
while((row=mysql_fetch_row(res)))
{
for(int j=0;j {
printf("%s ",row[j]);
}
printf("\n");
}
if the MySQL query get a tuple whchi has field "NULL", then problem comes!
First, NULL in MySQL is not a value, it is a condition. So if you try and write something "= NULL" you'll get an empty set rather than the results you're looking for. Try "IS NULL" instead. For example, mysql> select * from demo_people left join demo_property on demo_people.pid = demo_property.pid where spid is NULL;
2. becaulful with this code:
while((row=mysql_fetch_row(res)))
{
for(int j=0;j
printf("%s ",row[j]);
}
printf("\n");
}
if the MySQL query get a tuple whchi has field "NULL", then problem comes!
Friday, November 9, 2007
string in C++ vs char* in C
The convertion between int, char, char*, string in C/C++.
char* -> int: atoi
int -> char*: itoa, sprintf
char* -> string: string.assign()
string -> char*: string.c_str()
Note: atoi takes only one parameter; itoa takes multiple parameters.
char* -> int: atoi
int -> char*: itoa, sprintf
char* -> string: string.assign()
string -> char*: string.c_str()
Note: atoi takes only one parameter; itoa takes multiple parameters.
Thursday, November 8, 2007
Tokenize a string
Usually people use strtok to tokenize a string. There is a char* delims in this function. However the effect may not as you expected. E.g., assume delims="and", "ya and you and wa" is tokenized as "y you w" instead of "ya you wa".
Here is the solution, thanks to the anonymous coders. I found this via Google.
Here is the solution, thanks to the anonymous coders. I found this via Google.
Fulltext Search in MySQL
There are some points I encountered during my experiements:
1. how to change ft_min_word_len for windows platform: add one line ft_min_word_len = 2 in my.ini file in MySQL installment directory
2. After we changed the ft_min_word_len variable, we have to rebuild the fulltext index by ALTER TABLE person ADD FULLTEXT(name)
1. how to change ft_min_word_len for windows platform: add one line ft_min_word_len = 2 in my.ini file in MySQL installment directory
2. After we changed the ft_min_word_len variable, we have to rebuild the fulltext index by ALTER TABLE person ADD FULLTEXT(name)
Thursday, October 25, 2007
Some points...
1. No recommendation when coding in VS Studio 2005? try to check whether you left some important punctuation, such as ") ] } ; " etc
2. try to use FileWriteTuple(ofstream& ofs, string line) instead of FileWriteTuple(ofstream ofs, string line), just some feeling, no reason.
3. getline(infile, line, '\n') function will also count the line if the last line of the file has an enter return.
4. for checking whether an element exist in a set or not, there is a function named set::count handle it. No need to write your own function.
2. try to use FileWriteTuple(ofstream& ofs, string line) instead of FileWriteTuple(ofstream ofs, string line), just some feeling, no reason.
3. getline(infile, line, '\n') function will also count the line if the last line of the file has an enter return.
4. for checking whether an element exist in a set or not, there is a function named set::count handle it. No need to write your own function.
Saturday, February 10, 2007
Where C/C++ differ?
- Implicit assignment from void*: in C, is ok; in C++, not safe, cannot compile
- Freeing arrays: in C, use malloc and free for single elements and arrays; in C++, you much match calls to new/delete, new[]/delete[]
- Functions must be decleared before use
- struct: in C, you have to include keyword struct in order to declear a struct_instance; in C++, you don't have to do so.
- C++ has a much larger library: sometimes you want to compile a math heavy computation program, you could use gcc foo.c -lm/g++ foo.cc
- C didn't provide a boolean type, you could use enum to define.
- C++ may automatically add return 0 at the end of the main(); however in C you have to do it yourself.
- C requires define all the variables before a block of codes; C++ not necessary.
Subscribe to:
Posts (Atom)