Is any self reproducing code in C ?

S

Sweety

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,
 
M

Mike Wahler

Sweety said:
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
 
G

Gregory Pietsch

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
 
K

Kevin D. Quitt

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,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,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,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,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,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,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,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,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,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,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,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,w,#44,n);
write(#39#39#41,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#125);end.
{*/}
 
K

Kevin D. Quitt

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.
 
K

Kevin D. Quitt

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*/
??>
 
B

bogonic

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,k=-8,j=0;j<9;j++,jy3||(k+=8))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);for(i=0;i<5;i++,putchar(10))for(",
"p=dna;*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,k=-8,j=0;j<9;j++,j%3||(k+=8))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);for(i=0;i<5;i++,putchar(10))for(
p=dna;*p;++p)putchar(*p==120?34:*p==121?37:*p==122?92:*p);}

/* It's life Jim, but not as we know it! */
[/i][/i]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top