c program

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

    #1

    c program

    Hi
    I would like to know how to print the program itself as the output of
    that same program without using files...

    eg:
    #include<stdio. h>
    void main()
    {
    printf("hello") ;
    -
    -
    -
    -
    }

    This is the program. On execution of this program,the output should be

    #include<stdio. h>
    void main()
    {
    printf("hello") ;
    -
    -
    -
    -
    }

    thank you
    Reagrds
    Pravin
  • Serge Paccalin

    #2
    Re: c program

    Le mardi 18 janvier 2005 à 10:54, Pravin Shetty a écrit dans
    comp.lang.c :
    [color=blue]
    > Hi
    > I would like to know how to print the program itself as the output of
    > that same program without using files...[/color]

    Look for "quine" on the web.



    --
    ___________ 2005-01-18 12:18:47
    _/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
    \ \_L_) Il faut donc que les hommes commencent
    -'(__) par n'être pas fanatiques pour mériter
    _/___(_) la tolérance. -- Voltaire, 1763

    Comment

    • infobahn

      #3
      Re: c program

      Pravin Shetty wrote:[color=blue]
      >
      > Hi
      > I would like to know how to print the program itself as the output of
      > that same program without using files...[/color]

      Google for "quine"
      [color=blue]
      >
      > eg:
      > #include<stdio. h>
      > void main()[/color]

      int main(void)

      Comment

      • Jonathan Burd

        #4
        Re: c program

        Pravin Shetty wrote:
        [...][color=blue]
        > #include<stdio. h>
        > void main()[/color]
        Umm, Stop quining! Learn to not void main() first. This is what the C
        standard has to say about this:

        <quote>

        5.1.2.2.1 Program startup

        [#1] The function called at program startup is named main.
        The implementation declares no prototype for this function.
        It shall be defined with a return type of int and with no
        parameters:

        int main(void) { /* ... */ }

        or with two parameters (referred to here as argc and argv,
        though any names may be used, as they are local to the
        function in which they are declared):

        int main(int argc, char *argv[]) { /* ... */ }

        or equivalent;8) or in some other implementation-defined
        manner.

        </quote>
        [color=blue]
        > {
        > printf("hello") ;[/color]
        [...]
        Missing something important? `return 0;`
        [...]


        Regards,
        Jonathan.

        --
        C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
        C Library: http://www.dinkumware.com/refxc.html
        C99 Standard Draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

        "If unsigned integers look like two's complement (signed) integers,
        it's because two's complement integers look like unsigned integers."
        -Peter Nilsson

        Comment

        • Vig

          #5
          Re: c program


          "Serge Paccalin" <sp@mailclub.no .spam.net.inval id> wrote in message
          news:hc1d61h1dm 6l.dlg@canttouc hthis-127.0.0.1...[color=blue]
          > Le mardi 18 janvier 2005 à 10:54, Pravin Shetty a écrit dans
          > comp.lang.c :
          >[color=green]
          > > Hi
          > > I would like to know how to print the program itself as the output of
          > > that same program without using files...[/color]
          >
          > Look for "quine" on the web.
          >
          > http://www.nyx.net/~gthompso/self_c.txt[/color]

          Although I can't think of a way right now, I think he wants to reproduce
          custom code...

          -Vig


          Comment

          • Debian User

            #6
            Re: c program

            A simple example, ugly, but it works :)
            char*s="char*s= %c%s%c;main(){p rintf(s,34,s,34 );}";main(){pri ntf(s,34,s,34); }

            Pravin Shetty <pra_m_shetty@r ediffmail.com> wrote:[color=blue]
            > Hi
            > I would like to know how to print the program itself as the output of
            > that same program without using files...
            >
            > eg:
            > #include<stdio. h>
            > void main()
            > {
            > printf("hello") ;
            > -
            > -
            > -
            > -
            > }
            >
            > This is the program. On execution of this program,the output should be
            >
            > #include<stdio. h>
            > void main()
            > {
            > printf("hello") ;
            > -
            > -
            > -
            > -
            > }
            >
            > thank you
            > Reagrds
            > Pravin[/color]

            Comment

            • Jonathan Burd

              #7
              Re: c program

              Debian User wrote:[color=blue]
              > A simple example, ugly, but it works :)
              > char*s="char*s= %c%s%c;main(){p rintf(s,34,s,34 );}";main(){pri ntf(s,34,s,34); }
              >[/color]
              [...]

              Please do not toppost in c.l.c. The regulars here seem to dislike it.
              Secondly, topposting blurs the context.

              --
              C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
              C Library: http://www.dinkumware.com/refxc.html
              C99 Standard Draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

              "I'm learning to program, because then,
              I can write programs to do my homework faster." - Andy Anfilofieff

              Comment

              • Debian User

                #8
                Re: c program

                Jonathan Burd <jonathan.burd@ gmail.com> wrote:[color=blue]
                > Debian User wrote:[color=green]
                >> A simple example, ugly, but it works :)
                >> char*s="char*s= %c%s%c;main(){p rintf(s,34,s,34 );}";main(){pri ntf(s,34,s,34); }
                >>[/color]
                > [...]
                >
                > Please do not toppost in c.l.c. The regulars here seem to dislike it.
                > Secondly, topposting blurs the context.
                >[/color]
                sorry, I was used to post in BBS :(
                I am new here and not very clear with something

                Comment

                Working...