Wednesday 18 September 2013

Programming: How to Write a C Program to Print its Own Code?

7:05 pm

Ever wondered how to write a C program to print its own source code? Well, here is the source code of a C program that when executed will print its own source code. In other words, the output of this program is exactly same as its source code.
Here’s the program:
#include<stdio.h>
char *program=”#include<stdio.h>%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}
I hope you would like this post!

This post was originally posted on GoHacking.com.

Written by

I'm a student of Computer Sciences. I love to explore, gain and share knowlegde and other Geeky Stuff. I love Programming, Computer Networking, Flash Animating, Watching and Playing Cricket.

0 comments:

Post a Comment

Comments and Suggestions are Welcomed !

 

© 2013 GEEK's Radar. All Rights Resevered by the Original Owners of thr Data and/or Information and/or Stats used on this Blog. Designed by Templateism

Back To Top