Friday, August 19, 2011

Writing C/C++ code in Vi Editor

Vi Editor happens to be one of the oldest editors which is still shipped with all the flavors of Linux. It was written by Bill_Joy of the Sun Micro systems and Java fame. It was written using the favorite C language and now I am going to show you how to write and edit C code in the Vi editor and them compile it in the shell using the famous GCC compiler.

1. First you fire up your Linux machine. Open your terminal window

2. Type vi
If the file exists , it will be reopened and if the file does not exists it will be created and blank page will be open



3. Press 'i' or Insert button in your keyboard. SO that you are in writing mode from command  mode. Generally Vi Editor was designed to be used completely from the keyboard , hence Vi editor has loads commands. A list of such commands can be found here.

4. Also you can try out a book called Mastering Vi . You can get this book HERE.

5. After you have finished writing your C code. You can press ESC in your keyboard and return back to command mode. Write ":wq" (without quotes) in the command mode . the 'w' command is used to save the file and 'q' command is used to quit the editor and return to the shell. When both the commands are fused together, it will save the file and quit from the editor to the shell.



6. Type the command : "gcc " and press Enter. If your program has no syntax error , then you will end up with another prompt.



7. Then type "./a.out' and press Enter. You can see the output of your code ;)



EXCEPTIONS.....

If you are bored of continuously giving in ./a.out , then you can type :gcc -o and press Enter.

Then you can type filename.out in the prompt and get the output.


If your code is not bug free  then you type in "vi " into the shell which will again open up your vi editor and you can recheck your code and then follow the above procedure.

                                                                                                                 Adieu

HOW TO DESTROY AN ORGANIZATION????

Recently I am interested in knowing how to destroy a company or an organization. I am hell into searching to know how best can someone from the outside come and disrupt a company to bankruptcy and then end it totally....

Not in a way such as the person gets into an organization and then breaks it down but someone from the outside does it.

If YOU guys have any idea then please please please do inform me in this blog as a comment..

                ADIEU