Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Friday, October 23, 2009

A Program To print it's own source code:

You know how to print source code of own program. This is the one of the
interview question. Here is the program to print its own source code.
void main()
{
FILE *f;
char c;
f=fopen("file_name.c","r");
c=fgetc(f);
while(c!=EOF)
{
putc(c,stdout);
c=fgetc(f);
}
getch();
}

Instead of file_name.c give your source code file name. This program will
print the source code of the same program.