• Re: A self-printing program (quine)

    From Muttley@DastartdlyHQ.org@21:1/5 to All on Fri Nov 15 13:54:15 2024
    On Fri, 15 Nov 2024 20:45:58 +0800
    wij <wyniijj5@gmail.com> boring babbled:
    A self-printing program (quine).

    Hell it is. It has to print out the whole code, not just the main() function.

    Heres one that actually works:

    #include <stdio.h>
    #include <string.h>

    int main()
    {
    char *prog="#include <stdio.h>$#include <string.h>$$int main()${$
    char *prog=@?@;$ char *c;$$ for(c=prog;*c;++c)$ {$
    switch(*c)$ {$ case 36:$
    putchar(10);$ break;$ case 64:$
    putchar(34);$ break;$ c
    ase 63:$ printf(@%s@,prog);$ break
    ;$$ default:$ putchar(*c);$
    }$ }$ return 0;$}$";
    char *c;

    for(c=prog;*c;++c)
    {
    switch(*c)
    {
    case 36:
    putchar(10);
    break;
    case 64:
    putchar(34);
    break;
    case 63:
    printf("%s",prog);
    break;
    default:
    putchar(*c);
    }
    }
    return 0;
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From red floyd@21:1/5 to Muttley@DastartdlyHQ.org on Fri Nov 15 19:39:08 2024
    On 11/15/2024 5:54 AM, Muttley@DastartdlyHQ.org wrote:

    Heres one that actually works:

    #include <stdio.h>
    #include <string.h>

    int main()
    {
    char *prog="#include <stdio.h>$#include <string.h>$$int main()${$
    char *prog=@?@;$ char *c;$$ for(c=prog;*c;++c)$ {$
    switch(*c)$ {$ case 36:$
    putchar(10);$ break;$ case 64:$
    putchar(34);$ break;$ c
    ase 63:$ printf(@%s@,prog);$ break
    ;$$ default:$ putchar(*c);$
    }$ }$ return 0;$}$";
    char *c;

    for(c=prog;*c;++c)
    {
    switch(*c)
    {
    case 36:
    putchar(10);
    break;
    case 64:
    putchar(34);
    break;
    case 63:
    printf("%s",prog);
    break;
    default:
    putchar(*c);
    }
    }
    return 0;
    }

    I believe you can elide the #include <string.h> texts.

    As to the OP, yeah, not only that, but we have no clue what's in "Wy.h"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@dastardlyhq.com@21:1/5 to All on Sat Nov 16 11:38:48 2024
    On Fri, 15 Nov 2024 19:39:08 -0800
    red floyd <no.spam.here@its.invalid> gabbled:
    On 11/15/2024 5:54 AM, Muttley@DastartdlyHQ.org wrote:

    Heres one that actually works:

    #include <stdio.h>
    #include <string.h>

    int main()
    {
    char *prog="#include <stdio.h>$#include <string.h>$$int main()${$ >> char *prog=@?@;$ char *c;$$ for(c=prog;*c;++c)$ {$
    switch(*c)$ {$ case 36:$
    putchar(10);$ break;$ case 64:$ >> putchar(34);$ break;$
    c
    ase 63:$ printf(@%s@,prog);$
    break
    ;$$ default:$ putchar(*c);$
    }$ }$ return 0;$}$";
    char *c;

    for(c=prog;*c;++c)
    {
    switch(*c)
    {
    case 36:
    putchar(10);
    break;
    case 64:
    putchar(34);
    break;
    case 63:
    printf("%s",prog);
    break;
    default:
    putchar(*c);
    }
    }
    return 0;
    }

    I believe you can elide the #include <string.h> texts.

    Yes, you're right. I think I needed in an earlier version for some library function which I managed to get rid of.

    As to the OP, yeah, not only that, but we have no clue what's in "Wy.h"

    Indeed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)