Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

hartnn

Write a program in C which outputs its own source code.

  • one year ago
  • one year ago

  • This Question is Closed
  1. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    i don't want the exact code, just discuss different logic with which we can do this....

    • one year ago
  2. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Sounds pretty crazy...

    • one year ago
  3. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    yes...

    • one year ago
  4. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Lets see now....

    • one year ago
  5. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    And the source code has to actually do something itself huh?

    • one year ago
  6. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    no restriction...it can do something else....or it can just output its own source code...

    • one year ago
  7. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Cuz technically you could just write a whole bunch of nonsense as a string ansd then print that :P.

    • one year ago
  8. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Idk why you would ever need to do this, is this some BS school assigment?

    • one year ago
  9. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    not assignment...just curious to know how..

    • one year ago
  10. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah I'm stumped on this one atm....

    • one year ago
  11. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    I asked on the code ranch for you, so lets see what they think up....

    • one year ago
  12. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    or just creating a billion print statements lol.

    • one year ago
  13. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    lol, a printf inside a printf inside a printf .....and so on..infinite printfs

    • one year ago
  14. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    na more like int i = 0; printf("int i = 0);

    • one year ago
  15. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    etc.

    • one year ago
  16. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    but you could literally do printf("code code code code more code yay code"); If the code doesn't have to run... 1 GIANT print statement...

    • one year ago
  17. duckhunt
    Best Response
    You've already chosen the best response.
    Medals 0

    Dont know if this will work... but u can try file functions (read and write or standard output)... (assuming u are going to save the source code file first) just ask your code to read that file (source.c) and maybe buffer it in some array .. and then print it :P

    • one year ago
  18. duckhunt
    Best Response
    You've already chosen the best response.
    Medals 0

    errr... do u want this code to be platform independent?

    • one year ago
  19. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    I was also thinking that, but you would have to say what you want to write and read in :p.

    • one year ago
  20. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    How about taking argv[0], appending ".c", if the file exists, open it, getc/putc and close it?

    • one year ago
  21. across
    Best Response
    You've already chosen the best response.
    Medals 0

    This is like asking to build a screwdriver using a screwdriver. :P

    • one year ago
  22. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    I found this http://en.wikipedia.org/wiki/Quine_(computing)

    • one year ago
  23. hartnn
    Best Response
    You've already chosen the best response.
    Medals 1

    quine is interesting, but not in c. rsmith, can u elaborate ?

    • one year ago
  24. msmithhnova
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah, quine is an odd area of CS. This code will print everything but the include line. #include <stdio.h> int main() { char *s="int main() { char *s=%c%s%c; printf(s,34,s,34); }"; printf(s,34,s,34); }

    • one year ago
  25. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    C is a compiled language. The executing file isn't the source file. Therefore, the program becomes basically, a simple open a file read it in, output it and close the file. A simple guess for the source code file name is the executable file's name with ".c" appended.

    • one year ago
  26. KonradZuse
    Best Response
    You've already chosen the best response.
    Medals 0

    They have c++ you can change what's needed youself...e

    • one year ago
  27. DLS
    Best Response
    You've already chosen the best response.
    Medals 0

    Hint: You can save the code onto a textfile and thereafter display it directly via simple input functions :)

    • one year ago
  28. DLS
    Best Response
    You've already chosen the best response.
    Medals 0

    http://en.wikipedia.org/wiki/Quine_(computing)

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.