Is any self reproducing code in C ?

Discussion in 'C Programming' started by Sweety, Aug 23, 2004.

  1. Sweety

    Sweety Guest

    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,
     
    Sweety, Aug 23, 2004
    #1
    1. Advertising

  2. Sweety

    Mike Wahler Guest

    "Sweety" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Aug 23, 2004
    #2
    1. Advertising

  3. (Sweety) wrote in message news:<>...
    > 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
     
    Gregory Pietsch, Aug 24, 2004
    #3
  4. 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.
    {*/}

    --
    #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
     
    Kevin D. Quitt, Aug 25, 2004
    #4
  5. On 24 Aug 2004 15:37:32 -0700, (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
     
    Kevin D. Quitt, Aug 26, 2004
    #5
  6. 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
     
    Kevin D. Quitt, Aug 26, 2004
    #6
  7. Sweety

    bogonic Guest

    (Sweety) wrote in message news:<>...
    > 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==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==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! */
     
    bogonic, Aug 26, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    601
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    606
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    415
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    386
    falcon
    Jul 31, 2005
  5. Replies:
    11
    Views:
    761
    Tor Rustad
    May 18, 2007
Loading...

Share This Page