CrazyEngineers Forum

******************************************
Welcome To CrazyEngineers (CE) – an online community of engineers from all over the world! With the younger CEan at 84 and the youngest at 16, CE boasts of professional engineers, students, professors, entrepreneurs, CEOs, geeks & nerds. We exchange innovative ideas, share knowledge, help each other and expand our worldwide network of engineers! You need not have a formal degree in engineering to be a part of CrazyEngineers! Need we say more?
Join CE! | Be a CE Ambassador! | Forgot password? | Sponsor CE | Contact Us
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Reply

  #1 (permalink)
Old 24th August 2008, 08:47 PM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Lightbulb C Challenge: Self-Printing Program

Source: Programming Challenges - Self-Printing Program - Cprogramming.com


Here's a nice challenge for all you programming freaks.

Write a program that, when run, will print out its source code. This source code, in turn, should compile and print out itself.


Discuss the code with fellow CEans in this thread. Googling is good, but it doesn't add value to your knowledge.
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)
Old 25th August 2008, 02:26 PM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Default Re: C Challenge: Self-Printing Program

Hah, No one?

Too tough?
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)
Old 25th August 2008, 02:40 PM
ash
Moderator
 
ash's Avatar
 
I'm a Crazy Communications Engineer
Join Date: 12th July 2007
Location: IIUM, Malaysia
Posts: 1,506
Default Re: C Challenge: Self-Printing Program

That sounds doable Have a function to copy itself and read out its source code.

*rubs chin*
__________________
Keep it simple. Keep it real.
| New to CE? Click here! | Join our CE Bot project! | Problems? Questions? PM or mail me at ash{at]crazyengineers{dot]com |
ash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)
Old 25th August 2008, 04:31 PM
CE - Addict
 
anuragh27crony's Avatar
 
I'm a Crazy Computer Engineer
Join Date: 12th January 2006
Location: INDIA
Posts: 301
Send a message via Yahoo to anuragh27crony
Default Re: C Challenge: Self-Printing Program

Good question...this question i have encountered....during my placements.....

Simple technique is ...to use %s in a pointer to char which contains itself while printing.

char *temp="include<stdio.h> void main() { char *temp=%s ...and so on";
anuragh27crony is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)
Old 26th August 2008, 12:24 AM
CE - Regular Member
 
I'm a Crazy Electronics and Communication Engineer
Join Date: 19th March 2007
Location: Jeddah, Saudi Arabia
Posts: 72
Send a message via AIM to bayazidahmed Send a message via MSN to bayazidahmed Send a message via Yahoo to bayazidahmed
Default Re: C Challenge: Self-Printing Program

Quote:
Originally Posted by The_Big_K View Post
Hah, No one?

Too tough?
Nah! Too easy.
bayazidahmed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)
Old 26th August 2008, 12:43 AM
Good Administrator
 
The_Big_K's Avatar
 
I'm a Crazy Electrical Engineer
Join Date: 26th November 2005
Location: Terra-Firma
Posts: 4,996
Send a message via Yahoo to The_Big_K
Default Re: C Challenge: Self-Printing Program

Alright, alright!

Why don't you help others come up with a solution then?
The_Big_K is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 10:32 PM.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.Ad Management by RedTyger