20 March, 2011

Useful tips in VIM Editore.

1. If you want to split the screen horizontally give command
:split
If you want to split the screen vertically give command
:vsplit
If you want to open an new/other exiting file in splited window give command
:new filename for horizontal window
:vnew filename for vertical window.
If you want to quit all window give command
:qall for quitting without saving the changes
:wqall for quitting with saving the changes
You can use normal quitting command for one particular splitted window like
q,wq
To move between the splitted window , use ctrl+ww

2. Folding techniques:
You can fold a block of code of a long file. The block can be anything like (),{},[]
or may be some code between the lines.
For example:
Suppose this is your code:
#include
.........................
.......
int main(void)
{
----
----
----
for(;;){

-----
-----
}
}

To fold the brackets {} of for loop, keep the cursor at opening bracket of the for loop and then use zfa} command. It will make a fold till the closing of the corresponding bracket. This technique also works form backward.
It means you can keep the cursor at the closing bracket and use command zfa{ .
For closing and opening the folds, move the cursor at the fold and use command za
If you want to fold the codes between particular lines , Use command
:beginning_line,closing_line fold
Give a space between closing line and fold command.You can also use fo instead of fold.

For more details about this folding option just visit the link.
http://www.linux.com/archive/feature/114138

17 March, 2011

Puzzle

You are given two ropes and a lighter. This is the only equipment you can use. You are told that each of the two ropes has the following property: if you light one end of the rope, it will take exactly one hour to burn all the way to the other end. But it doesn’t have to burn at a uniform rate. In other words, half the rope may burn in the first five minutes, and then the other half would take 55 minutes. The rate at which the two ropes burn is not necessarily the same, so the second rope will also take an hour to burn from one end to the other, but may do it at some varying rate, which is not necessarily the same as the one for the first rope. Now you are asked to measure a period of 45 minutes. How will you do it?

15 March, 2011

strdup() and strcpy()

whats the difference between strdup() and strcpy()? In which case, which of this is preferred????

08 March, 2011

#ifdef __cplusplus

#ifdef __cplusplus
extern "C" {
#endif

.............
............
. .
.
.
.
#ifdef __cplusplus
}
#endif

i have seen this piece of code in many files esp in header files... any idea what does this mean and when to use this????

06 March, 2011

difference between strcpy() and memcpy()???

What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?