Thread Closed

Self writing program and long string assignment in C

 
Share Thread Thread Tools
Jun13-08, 09:58 AM   #1
 

Self writing program and long string assignment in C


I would like to write a C program that writes itself to the screen (without reading from disk).
My idea is to assign text to a string S, split it into two parts S1 and S2 and then write each part twice. If S1 is made equal to program part before text definition and S2 equal to program part after, then the program would write S1S1S2S2, which would be equal to the whole program.

However I don't know how to put a text into the string S. I tried to use strcpy, but it does not work if the text is too long for a single line. Is there a way to store a several line long text into a string without spliting the text (the whole text should be written inside a single "").
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> King Richard III found in 'untidy lozenge-shaped grave'
>> Google Drive sports new view and scan enhancements
>> Researcher admits mistakes in stem cell study
Jun13-08, 10:11 AM   #2
 
Recognitions:
Homework Helper Homework Help
How is the text entered into the program? Is it by human input?
Jun13-08, 05:03 PM   #3
 
Yes, text should be typed directly into the source code. Of course it would be much easier if it would be read from a file, but then this task would not be interesting. The tricky part is that any character added to the text is simultaneously added to the whole program, so we must find a way to output more information that we explicitly define.
Jun13-08, 05:37 PM   #4
 

Self writing program and long string assignment in C


In the general terminology of computer programming languages this feature is called "line continuation".

This can be accomplished in C++ by backslash \ followed by a newline.

http://msdn.microsoft.com/en-us/library/69ze775t.aspx
Jun13-08, 05:56 PM   #5
 
Admin
Quine revisted? Or am I missing something?

http://www.physicsforums.com/showthread.php?t=237064

I believe there are examples in Wiki.

Borek
--
http://www.chembuddy.com
http://www.ph-meter.info
Jun16-08, 03:43 AM   #6
 
Recognitions:
Homework Helper Homework Help
Yeah it's probably quine. Apparently I misread the first line of the OP.
Jun16-08, 03:52 PM   #7
 
Thanks for the answers (and sorry for not checking for similar posts on this forum). I read the example on wikipedia and now understand how this program can be constructed.
However my first idea about printing S1S1S2S2 would not work: I forgot that printf does not print all characters in a quotation (for example \ used for line continuation or before special characters).
Thread Closed
Thread Tools


Similar Threads for: Self writing program and long string assignment in C
Thread Forum Replies
tech writing assignment Computing & Technology 0
You know you've been writing essays for too long when... General Discussion 3
Math/Science symbols, program for writing them Computing & Technology 1
program for writing equations / expressions Introductory Physics Homework 3
help with writing a program Computing & Technology 2