Home  |  Contact   
You are viewing: Coding Posts

Geekcode

April 24th, 2008 by Vineet | No Comments »

While playing around with the synaptic package manager on my Debian I came across this thing called geekcode. It was developed by Robert Hayden in 1993. The official geekcode website is at http://www.geekcode.com. It’s a code used by geeks to depict their personal profile. It tells about ones preferences, physical structure, relationship status, etc.
Some geeks also used it as their signature.
A nice thing to know if you are a geek.
If you want to make your geekcode just install the geekcode program on your system and run it. You will understand what to do if you are geek enough.

BTW below is my geekcode ;)

—–BEGIN GEEK CODE BLOCK—–
Version: 3.12
GAT d- s:+ a– C+++ UL++ P+ L+++ E– W+++ N+ o+ K w–
O++ M- V- PS+ PE+ Y+ PGP- t+ 5 X R- tv– b+ DI++ D+
G++ e++ h* !r y
——END GEEK CODE BLOCK——

Topics: Coding, Humour, Softwares, Uncategorized Email This Email This
AddThis Social Bookmark Button

 

A C Programme without main function !!

March 9th, 2008 by Sita | No Comments »

How to write a C program without a main function.Is it possible to do that.. OK.. heres the code

#include

#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()
{
printf(” hello “);
}

Yes the above program runs perfectly fine.But how,whats the logic behind it?

Here we are using preprocessor directive #define with arguments.The ‘##’ operator is called the token pasting or token merging operator.That is we can merge two or more characters with it.

NOTE: A Preprocessor is program which processess the source code before compilation.

Look at the 2nd line of program-

#define decode(s,t,u,m,p,e,d) m##s##u##t

What is the preprocessor doing here.The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut).The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens).

Now look at the third line of the program-

#define begin decode(a,n,i,m,a,t,e)

Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e).According to the macro definition in the previous line the argument must de expanded so that the 4th,1st,3rd & the 2nd characters must be merged.In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.

So the third line “int begin()” is replaced by “int main()” by the preprocessor before the program is passed on for the compiler.That’s it…

The bottom line is there can never exist a C program without a main() function.Here we are just playing a gimmick that makes us beleive the program runs without main function.But here we are using the proprocessor directive to intelligently replace the word begin” by “main” .

Topics: Coding Email This Email This
AddThis Social Bookmark Button

 

Convert a webpage into pdf

February 18th, 2008 by Sita | 1 Comment »






Topics: Coding Email This Email This
AddThis Social Bookmark Button

 

Great GDB tutorial…

February 5th, 2008 by Vineet | No Comments »

GDB (Acronym for GNU debugger) is considered to be one of the best debuggers among the geek community. i generally prefer debugging my programs without any debugging tools , i.e by mental inspection and printf()s. I feel this is the best approach for a student…It makes you learn a lot. But when you have to debug a more than 1000 lines code and you have deadlines to meet you practically can’t do without a debugger.
GDB is a command line based tool but really powerful and helpful.
I found a great comprehensive tutorial on GDB here ( http://www.dirac.org/linux/gdb/ )
PS: don’t leave chapter 2 of this tutorial. Even if you don’t want to learn about gdb, still read chapter 2 of this tutorial …. Read it to know why.

Hail GNU !!!

Topics: Coding, Open Source, Tools Email This Email This
AddThis Social Bookmark Button

 

The History of “Hello World”

January 31st, 2008 by Vineet | No Comments »

Almost all of you who have studied even a little bit of programming must identify these words “hello world”. I am pretty sure the first program you read printed these words on the screen.

The first known instance of the usage of the words “hello” and “world” together in computer literature occurred earlier, in Kernighan’s 1972 Tutorial Introduction to the Language B, with the following code:


main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';

Then it was used as the first program in the famous book “The C programming Language” by Kernighan and Ritchie.
The code is below :

main() {
printf("hello, world\n");
}

For a detailed information on Hello World programs check out this link on wikipedia

It’s not necessary to have a big thing to make history !!!

Topics: Coding Email This Email This
AddThis Social Bookmark Button

 

Java Code Search Engines

January 15th, 2008 by Sita | No Comments »

Good programmers write what thay can. Great programmers write what they must. If you believe in the above saying then you will love the following list of websites that allow you to find code that you can do Ctrl-C, Ctrl-V :)

javadb.com is my favorite code search engine. It has got list of questions like

You can select the question that best describes your problem and you will have a ready-made code to solve your issue.

if you want to know how to use a particular class then Jexamples is a good site for the same.

Topics: Coding Email This Email This
AddThis Social Bookmark Button