Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Is any self reproducing code in C ?

Reply
Thread Tools

Is any self reproducing code in C ?

 
 
Sweety
Guest
Posts: n/a
 
      08-23-2004
hello experts ,
Is there any .exe file which creates the output of the
source code in .c file itself .
Condition is that instead of there is no .c file in same path the .exe
file itself prints the output of source .

Waiting for the best reply ,
bye,
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      08-23-2004

"Sweety" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> hello experts ,
> Is there any .exe file which creates the output of the
> source code in .c file itself .
> Condition is that instead of there is no .c file in same path the .exe
> file itself prints the output of source .


Google for "quine".

-Mike


 
Reply With Quote
 
 
 
 
Gregory Pietsch
Guest
Posts: n/a
 
      08-24-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (Sweety) wrote in message news:<(E-Mail Removed). com>...
> hello experts ,
> Is there any .exe file which creates the output of the
> source code in .c file itself .
> Condition is that instead of there is no .c file in same path the .exe
> file itself prints the output of source .
>
> Waiting for the best reply ,
> bye,


Yes, there are many C quines. This is a strictly conforming one:

char*a??(??)=??<
"??=include",
"??=include",
"??=define o stdout",
"??=define b break;case",
"??=define s(p)fputs(p,o);",
"??=define c(p)fputc(p,o);",
"void t(p,f)char*p;????/")b'??(':s(??/"???/??/?(??/")b'??)'",
":s(??/"???/??/?)??/")b'??/??/??/??/':f&&s(??/"???/??/?/??/")",
"s(??/"???/??/?/??/")b'??/??/n':if(f)s(??/"???/??/?/n??/")",
"else case'??/"':if(f)s(??/"???/??/?/??/??/??/"??/")",
"else default:c(*p)??>??>??>main()??;??/",0);for(p=a",
";*p;p++)t(*p,0);exit(!ferror(o)&&",
"!fclose(o)?EXIT_SUCCESS",
":EXIT_FAILURE);",
"/*NOTREACHED*/",
"??>",
0??>;
??=include
??=include
??=define o stdout
??=define b break;case
??=define s(p)fputs(p,o);
??=define c(p)fputc(p,o);
void t(p,f)char*p;??':s("???/?>")b'??(':s("???/?(")b'??)'
:s("???/?)")b'??/??/':f&&s("???/?/")
s("???/?/")b'??/n':if(f)s("???/?/n")
else case'"':if(f)s("???/?/??/"")
else default:c(*p)??>??>??>main()??;",0);for(p=a
;*p;p++)t(*p,0);exit(!ferror(o)&&
!fclose(o)?EXIT_SUCCESS
:EXIT_FAILURE);
/*NOTREACHED*/
??>

Gregory Pietsch
 
Reply With Quote
 
Kevin D. Quitt
Guest
Posts: n/a
 
      08-25-2004
Give this to your teacher:

(*a);int main(void){char i,*s[]={"%c%s%c%c%c",
"(*a);int main(void){char i,*s[]={",
"%c%c%c%s%c%s%c%s%c%s%c/*%c%s",
";printf(s[1]);for(i=0;i<=12;i++)printf(s[0],34,s[i],34,44,10);",
"printf(s[2],34,34,125,s[3],10,s[4],10,s[5],10,s[6],10,41,s[7]);",
"for(i=0;i<=12;i++)printf(s[0],39,s[i],39,44,10);",
"printf(s[12],39,39,41,s[8],10,s[9],10,s[10],10,s[11],10,47,125);",
"const q=#34;w=#39;n=#13#10;s:array[0..13] of string=(",
";var i:integer;begin write(s[1]);for i:=0to 12do write(q,s[i],q,#44,n);",
"write(#34#34#125,s[3],n,s[4],n,s[5],n,s[6],n,#47#42#41,s[7]);",
"for i:=0to 12do write(w,s[i],w,#44,n); ",
"write(#39#39#41,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#125);end.",
"%c%c%c%s%c%s%c%s%c%s%c{*%c%c",
""};printf(s[1]);for(i=0;i<=12;i++)printf(s[0],34,s[i],34,44,10);
printf(s[2],34,34,125,s[3],10,s[4],10,s[5],10,s[6],10,41,s[7]);
for(i=0;i<=12;i++)printf(s[0],39,s[i],39,44,10);
printf(s[12],39,39,41,s[8],10,s[9],10,s[10],10,s[11],10,47,125);
/*)const q=#34;w=#39;n=#13#10;s:array[0..13] of string=('%c%s%c%c%c',
'(*a);int main(void){char i,*s[]={',
'%c%c%c%s%c%s%c%s%c%s%c/*%c%s',
';printf(s[1]);for(i=0;i<=12;i++)printf(s[0],34,s[i],34,44,10);',
'printf(s[2],34,34,125,s[3],10,s[4],10,s[5],10,s[6],10,41,s[7]);',
'for(i=0;i<=12;i++)printf(s[0],39,s[i],39,44,10);',
'printf(s[12],39,39,41,s[8],10,s[9],10,s[10],10,s[11],10,47,125);',
'const q=#34;w=#39;n=#13#10;s:array[0..13] of string=(',
';var i:integer;begin write(s[1]);for i:=0to 12do write(q,s[i],q,#44,n);',
'write(#34#34#125,s[3],n,s[4],n,s[5],n,s[6],n,#47#42#41,s[7]);',
'for i:=0to 12do write(w,s[i],w,#44,n); ',
'write(#39#39#41,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#125);end.',
'%c%c%c%s%c%s%c%s%c%s%c{*%c%c',
'');var i:integer;begin write(s[1]);for i:=0to 12do write(q,s[i],q,#44,n);
write(#34#34#125,s[3],n,s[4],n,s[5],n,s[6],n,#47#42#41,s[7]);
for i:=0to 12do write(w,s[i],w,#44,n);
write(#39#39#41,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#125);end.
{*/}

--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
 
Reply With Quote
 
Kevin D. Quitt
Guest
Posts: n/a
 
      08-26-2004
On 24 Aug 2004 15:37:32 -0700, (E-Mail Removed) (Gregory Pietsch) wrote:
>Yes, there are many C quines. This is a strictly conforming one:


Are you sure that wasn't corrupted at some point? And I don't mean
because of the trigraphs.


--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
 
Reply With Quote
 
Kevin D. Quitt
Guest
Posts: n/a
 
      08-26-2004
Hah! It was. From <http://www0.us.ioccc.org/1990/scjones.c>

char*a??(??)=??<
"??=include<stdio.h>",
"??=include<stdlib.h>",
"??=define o stdout",
"??=define b break;case",
"??=define s(p)fputs(p,o);",
"??=define c(p)fputc(p,o);",
"void t(p,f)char*p;??<f&&c('??/"')",
"for(;;p++)??<switch(*p)??<case 0:f&&",
"s(??/"??/??/??/",??/")c('??/??/n')return;case",
"'??=':s(??/"???/??/?=??/")b'??<':s(??/"???/??/?<??/")",
"b'??>':s(??/"???/??/?>??/")b'??(':s(??/"???/??/?(??/")b'??)'",
":s(??/"???/??/?)??/")b'??/??/??/??/':f&&s(??/"???/??/?/??/")",
"s(??/"???/??/?/??/")b'??/??/n':if(f)s(??/"???/??/?/n??/")",
"else case'??/"':if(f)s(??/"???/??/?/??/??/??/"??/")",
"else default:c(*p)??>??>??>main()??<char**p",
";t(??/"char*a??(??)=??<??/",0);for(p=a;*p",
";p++)t(*p,1);t(??/"0??>;??/",0);for(p=a",
";*p;p++)t(*p,0);exit(!ferror(o)&&",
"!fclose(o)?EXIT_SUCCESS",
":EXIT_FAILURE);",
"/*NOTREACHED*/",
"??>",
0??>;
??=include<stdio.h>
??=include<stdlib.h>
??=define o stdout
??=define b break;case
??=define s(p)fputs(p,o);
??=define c(p)fputc(p,o);
void t(p,f)char*p;??<f&&c('"')
for(;;p++)??<switch(*p)??<case 0:f&&
s("??/",")c('??/n')return;case
'??=':s("???/?=")b'??<':s("???/?<")
b'??>':s("???/?>")b'??(':s("???/?(")b'??)'
:s("???/?)")b'??/??/':f&&s("???/?/")
s("???/?/")b'??/n':if(f)s("???/?/n")
else case'"':if(f)s("???/?/??/"")
else default:c(*p)??>??>??>main()??<char**p
;t("char*a??(??)=??<",0);for(p=a;*p
;p++)t(*p,1);t("0??>;",0);for(p=a
;*p;p++)t(*p,0);exit(!ferror(o)&&
!fclose(o)?EXIT_SUCCESS
:EXIT_FAILURE);
/*NOTREACHED*/
??>

--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
 
Reply With Quote
 
bogonic
Guest
Posts: n/a
 
      08-26-2004
(E-Mail Removed) (Sweety) wrote in message news:<(E-Mail Removed). com>...
> hello experts ,
> Is there any .exe file which creates the output of the
> source code in .c file itself .
> Condition is that instead of there is no .c file in same path the .exe
> file itself prints the output of source .


char*b=
" "
" "
" ## "
" ## "
" # "
" "
" "
" "
,*dna[]={
"};main(){int i,j,k,n;char*p;puts(xchar*b=x);for(i=0;i<64;i++,i& 7||puts(xzxx))",
"{i&7||putchar(34);for(n=-b[i],k=-8,j=0;j<9;j++,jy3||(k+=)n+=b[(i+k&56)",
"|(i+jy3-1&7)];putchar(x #x[n==262&&b[i]==35||n==265]);}puts(x,*dna[]={x);for",
"(i=0;i<5;i++)printf(xzxyszx,znx,dna[i]);for(i=0;i<5;i++,putchar(10))for(",
"p=dna[i];*p;++p)putchar(*p==120?34:*p==121?37:*p==122?92:* p);}",
};main(){int i,j,k,n;char*p;puts("char*b=");for(i=0;i<64;i++,i& 7||puts("\""))
{i&7||putchar(34);for(n=-b[i],k=-8,j=0;j<9;j++,j%3||(k+=)n+=b[(i+k&56)
|(i+j%3-1&7)];putchar(" #"[n==262&&b[i]==35||n==265]);}puts(",*dna[]={");for
(i=0;i<5;i++)printf("\"%s\",\n",dna[i]);for(i=0;i<5;i++,putchar(10))for(
p=dna[i];*p;++p)putchar(*p==120?34:*p==121?37:*p==122?92:* p);}

/* It's life Jim, but not as we know it! */
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Self-reproducing program in Ken Thompson's Turing paper lovecreatesbea...@gmail.com C Programming 11 05-18-2007 05:41 PM
__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code) falcon Python 0 07-31-2005 05:41 PM
Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code) Ralf W. Grosse-Kunstleve Python 2 07-12-2005 03:20 AM
Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code Ralf W. Grosse-Kunstleve Python 16 07-11-2005 09:28 PM
__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code) Ralf W. Grosse-Kunstleve Python 18 07-11-2005 04:01 PM



Advertisments