Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter




C Program - Source Code Generator


Posted Date: 24 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Arun Jadhav       Member Level: Diamond
Rating:     Points: 1



Many times the question asked in the interviews to write a program which creates it's source code as it's output. I have written the program please check it out.

Program:

#include"stdio.h"
#include"conio.h"
char *s="#include%c#include%cchar *s=%c%s%c;%cvoid main()%c{%cclrscr();%cprintf(s,10,10,34,s,34,10,10,10,10,10,10);%cgetch();%c}";
void main()
{
clrscr();
printf(s,10,10,34,s,34,10,10,10,10,10,10);
getch();
}





Responses

Author: Arun Jadhav    26 Mar 2008Member Level: Diamond   Points : 3
Simple form of above program can be written as:


#include"stdio.h"
#include"conio.h"
char *s="char *s=%c%s%c;%cmain(){printf(s,34,s,34,10);getch();}";
main(){printf(s,34,s,34,10);getch();}

Regards
Arun Jadhav



Author: Deepu    27 Mar 2008Member Level: Diamond   Points : 5
Hi Mr.Arun,

First of all congrats for finding out such an excellent programm.I did'nt checked it.But i will definitely try it out.What i want to know is

Can we write the same code for any other program for which we want to print the source code?I didnt meant the same code .I meant placing the code with %c's as above.

But where to place those %c's in the code inorder to get the source code as its output.

Please give me a reply,
With regards,
-Deepu


Author: Arun Jadhav    07 May 2008Member Level: Diamond   Points : 2
Hi Deepu,
Thank you for your interest in my program. I am giving the working of program. If you know this you will know where to use
%c.

Program:
#include"stdio.h"
#include"conio.h"
char *s="char *s=%c%s%c;%cmain(){printf(s,34,s,34,10);getch();}";
main(){printf(s,34,s,34,10);getch();}

Explanation:
I have written printf(s,34,s,34,10);
This can be wriiten as
printf("char *s=%c%s%c;%cmain(){printf(s,34,s,34,10);getch();}",34,s,34,10);

where 34 is the ASCII code for " and 10 is the ASCII code for \n character
So according to your program use %c for new line, printing " etc.

If you have any doubts then please reply.

Regards
Arun Jadhav



Author: Deepu    12 May 2008Member Level: Diamond   Points : 2
Hi Arun,
thanks for your concern and sending me reply for my doubt.you description is very nice and quite understandable.Once again you.

With regards,
Deepu.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: C Program of insertion and deletion in B tree
Previous Resource: C Program for insertion and deletion in heap
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources



Watch TV Channels
  • Watch Asianet TV online
  • Kairali TV in Internet
  • Surya TV online
  • Amritha TV Channel

  • Contact Us    Privacy Policy    Terms Of Use   

    SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.