Is any self reproducing code in C ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sweety

    Is any self reproducing code in C ?

    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,
  • Mike Wahler

    #2
    Re: Is any self reproducing code in C ?


    "Sweety" <sweety_elegant @yahoo.co.in> wrote in message
    news:113be981.0 408230824.7194e e0d@posting.goo gle.com...[color=blue]
    > 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 .[/color]

    Google for "quine".

    -Mike


    Comment

    • Gregory Pietsch

      #3
      Re: Is any self reproducing code in C ?

      sweety_elegant@ yahoo.co.in (Sweety) wrote in message news:<113be981. 0408230824.7194 ee0d@posting.go ogle.com>...[color=blue]
      > 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,[/color]

      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)?EXI T_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

      Comment

      • Kevin D. Quitt

        #4
        Re: Is any self reproducing code in C ?

        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#1 25,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#4 1,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#1 25);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#1 25,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#4 1,s[8],n,s[9],n,s[10],n,s[11],n,#123#42#47#1 25);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#12 5,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#1 25);end.
        {*/}

        --
        #include <standard.discl aimer>
        _
        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

        Comment

        • Kevin D. Quitt

          #5
          Re: Is any self reproducing code in C ?

          On 24 Aug 2004 15:37:32 -0700, GKP1@flash.net (Gregory Pietsch) wrote:[color=blue]
          >Yes, there are many C quines. This is a strictly conforming one:[/color]

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


          --
          #include <standard.discl aimer>
          _
          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

          Comment

          • Kevin D. Quitt

            #6
            Re: Is any self reproducing code in C ?

            Hah! It was. From <http://www0.us.ioccc.o rg/1990/scjones.c>

            char*a??(??)=?? <
            "??=include<std io.h>",
            "??=include<std lib.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++)??<s witch(*p)??<cas e 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)?EXI T_SUCCESS",
            ":EXIT_FAILURE) ;",
            "/*NOTREACHED*/",
            "??>",
            0??>;
            ??=include<stdi o.h>
            ??=include<stdl ib.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++)??<sw itch(*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.discl aimer>
            _
            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

            Comment

            • bogonic

              #7
              Re: Is any self reproducing code in C ?

              sweety_elegant@ yahoo.co.in (Sweety) wrote in message news:<113be981. 0408230824.7194 ee0d@posting.go ogle.com>...[color=blue]
              > 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 .[/color]

              char*b=
              " "
              " "
              " ## "
              " ## "
              " # "
              " "
              " "
              " "
              ,*dna[]={
              "};main(){i nt i,j,k,n;char*p; puts(xchar*b=x) ;for(i=0;i<64;i ++,i&7||puts(xz xx))",
              "{i&7||putchar( 34);for(n=-b[i],k=-8,j=0;j<9;j++,j y3||(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++)p rintf(xzxyszx,z nx,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(3 4);for(n=-b[i],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++)pr intf("\"%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! */

              Comment

              Working...