need help

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

    need help

    write a program in c.


  • Nick Keighley

    #2
    Re: need help

    On 10 Jul, 10:14, kevin <k...@nospam.in validwrote:
    write a program in c.
    you forgot the magic "p" word

    --
    Nick Keighley

    Error on line 0: Lazy programmer.

    Comment

    • Wolfgang Draxinger

      #3
      Re: need help

      kevin wrote:
      write a program in c.
      If that's some exercise and you want to cheat, then go to
      <http://kernel.org>, there you can get the sources of a
      particulary good programm written in C.

      But don't be surpreised, if you got a bad mark...

      If it shall be a bit simpler then a full blown OS kernel:

      #include <stdio.h>
      int main(int argc, char *argv[])
      {
      int i;
      for(i = 0; i < 42; ++i) {
      printf("%d, not the awnser to the question...\n", i);
      }
      return ++i;
      }

      That should do it, but I don't think you will profit from that
      example.

      Seriously: If this is a exercise, and you're a total newbie, then
      just crying "help" won't help you at all. Anything people can do
      is giving you some written examples of code and some explanation
      to it.

      Such things are commnly called textbooks and can be found in
      buildings called libraries and bought in bookshops, that come
      also in online form, one of them being <http://amazon.com>.

      But neither, an explanation given here, nor a textbook will take
      the work from you. It's still up to you to read the texts and
      also to understand them. I highly suggest, you read the book,
      and in the case of 'C' that would be "The C Programming
      Language" by Kernighan and Ritchie then.

      Once you've questions on thing you didn't understand reading the
      book, you're welcome to ask here, as long as you give detailed
      information about with which part you got a problem.

      Wolfgang Draxinger
      --
      E-Mail address works, Jabber: hexarith@jabber .org, ICQ: 134682867

      Comment

      • santosh

        #4
        Re: need help

        kevin wrote:
        write a program in c.
        Save the program below in a file called test.c. Invoke your favourite
        compiler and enjoy.

        #include "test.c"
        main(){}

        Comment

        • Keith Thompson

          #5
          Re: need help

          kevin <kev@nospam.inv alidwrites:
          write a program in c.
          Ok, done.

          If you're interested, the output was:
          Qb lbhe bja ubzrjbex

          Hope this helps, have a nice day.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          Nokia
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Walter Roberson

            #6
            Re: need help

            In article <g54otd$lo$1@re gistered.motzar ella.org>,
            santosh <santosh.k83@gm ail.comwrote:
            >kevin wrote:
            >
            >write a program in c.
            >
            >Save the program below in a file called test.c. Invoke your favourite
            >compiler and enjoy.
            >
            >#include "test.c"
            >main(){}
            Is this for C89 or C99? If it is for C99 then you need the 'int'
            on main. If it is for C89 then you should return a value from main.

            Recall, by the way, that compilers are permitted to impose limits on
            the depth of inclusions. For example,
            gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)
            with default options will expand to a total of 199 instances of main.


            --
            "The study of error is not only in the highest degree
            prophylatic, but it serves as a stimulating introduction to the
            study of truth." -- Walter Lipmann

            Comment

            • santosh

              #7
              Re: need help

              Walter Roberson wrote:
              In article <g54otd$lo$1@re gistered.motzar ella.org>,
              santosh <santosh.k83@gm ail.comwrote:
              >>kevin wrote:
              >>
              >>write a program in c.
              >>
              >>Save the program below in a file called test.c. Invoke your favourite
              >>compiler and enjoy.
              >>
              >>#include "test.c"
              >>main(){}
              >
              Is this for C89 or C99? If it is for C99 then you need the 'int'
              on main. If it is for C89 then you should return a value from main.
              The code is broken on purpose. :-)
              Recall, by the way, that compilers are permitted to impose limits on
              the depth of inclusions. For example,
              gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)
              with default options will expand to a total of 199 instances of main.
              Yes, and lcc-win apparently has a limit of 15. The Intel C compiler
              gives this amusing diagnostic:

              test.c(1): catastrophic error: #include file "test.c" includes itself
              #include "test.c"
              ^
              compilation aborted for test.c (code 4)

              BTW "test.c" can be replaced with __FILE__ to make the include directive
              immune to file renaming.

              Comment

              • John J. Smith

                #8
                Re: need help

                kevin wrote:
                write a program in c.
                Easy.

                /*
                * aprog.c
                *
                * "write a program in c."
                *
                */

                #include <stdio.h>
                #define in "\n"
                #define c

                int write(const char *foo)
                {
                signed int short bar = 0;
                const char *baz = foo;
                while(baz[bar]) putchar(bar[baz++]);
                return 0;
                }

                int main(void)
                {
                return write("a program" in c);
                }

                --
                John J. Smith
                Homework Expert

                Comment

                • Hans Schneider

                  #9
                  Re: need help

                  John J. Smith schrieb:
                  >kevin wrote:
                  >
                  >write a program in c.
                  >
                  >Easy.
                  >
                  >/*
                  * aprog.c
                  *
                  * "write a program in c."
                  *
                  */
                  >
                  >#include <stdio.h>
                  >#define in "\n"
                  >#define c
                  >
                  >int write(const char *foo)
                  >{
                  signed int short bar = 0;
                  const char *baz = foo;
                  while(baz[bar]) putchar(bar[baz++]);
                  return 0;
                  >}
                  >
                  >int main(void)
                  >{
                  return write("a program" in c);
                  >}
                  This program works not with LCC-WIN32 again! Why?

                  lc -ansic -pedantic -unused shadows -O aprog.c
                  Pedants aren't supported any more :-)
                  1 error

                  How do you do that? Not funny!

                  Comment

                  • Jens Thoms Toerring

                    #10
                    Re: need help

                    Hans Schneider <hans@localhost .localdomainwro te:

                    <program snipped>
                    This program works not with LCC-WIN32 again! Why?
                    lc -ansic -pedantic -unused shadows -O aprog.c
                    Pedants aren't supported any more :-)
                    1 error
                    Jacob Navia announced in a recent thread here in clc



                    that lcc-win no will longer have a '-pedantic' option (or, to be
                    precise, will output the above text if it's used). Since it's his
                    compiler he can do whatever he likes with it.
                    How do you do that? Not funny!
                    Better discuss that with Jacob in personal email (or in the lcc
                    newsgroup) unless you're trolling for another long-winded, use-
                    less and mostly off-topic thread here in clc;-)

                    Regards, Jens
                    --
                    \ Jens Thoms Toerring ___ jt@toerring.de
                    \______________ ____________ http://toerring.de

                    Comment

                    • Kenneth Brody

                      #11
                      Re: need help

                      kevin wrote:
                      >
                      write a program in c.
                      Done. What do I get?

                      --
                      +-------------------------+--------------------+-----------------------+
                      | Kenneth J. Brody | www.hvcomputer.com | #include |
                      | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                      +-------------------------+--------------------+-----------------------+
                      Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


                      Comment

                      • Hans Schneider

                        #12
                        Re: need help

                        Jens Thoms Toerring schrieb:
                        Hans Schneider <hans@localhost .localdomainwro te:
                        >
                        <program snipped>
                        >
                        >This program works not with LCC-WIN32 again! Why?
                        >
                        >lc -ansic -pedantic -unused shadows -O aprog.c
                        >Pedants aren't supported any more :-)
                        >1 error
                        >
                        Jacob Navia announced in a recent thread here in clc
                        >

                        >
                        that lcc-win no will longer have a '-pedantic' option (or, to be
                        precise, will output the above text if it's used). Since it's his
                        compiler he can do whatever he likes with it.
                        Sucks.

                        But, if I remove -pedantic, it works still not:

                        lc -ansic -unused -shadows -O aprog.c
                        Error aprog.c: 14 invalid type specification
                        1 error, 0 warnings
                        1 error

                        Is signed int short bar = 0; valid C?

                        Comment

                        • Richard Heathfield

                          #13
                          Re: need help

                          Hans Schneider said:

                          <snip>
                          Is signed int short bar = 0; valid C?
                          Yes.

                          --
                          Richard Heathfield <http://www.cpax.org.uk >
                          Email: -http://www. +rjh@
                          Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                          "Usenet is a strange place" - dmr 29 July 1999

                          Comment

                          • Dann Corbit

                            #14
                            Re: need help


                            "Hans Schneider" <hans@localhost .localdomainwro te in message
                            news:1355811T_d WV9SEqCh@localh ost.localdomain ...
                            Jens Thoms Toerring schrieb:
                            >
                            >Hans Schneider <hans@localhost .localdomainwro te:
                            >>
                            ><program snipped>
                            >>
                            >>This program works not with LCC-WIN32 again! Why?
                            >>
                            >>lc -ansic -pedantic -unused shadows -O aprog.c
                            >>Pedants aren't supported any more :-)
                            >>1 error
                            >>
                            >Jacob Navia announced in a recent thread here in clc
                            >>
                            >http://groups.google.com/group/comp....edants&lnk=ol&
                            >>
                            >that lcc-win no will longer have a '-pedantic' option (or, to be
                            >precise, will output the above text if it's used). Since it's his
                            >compiler he can do whatever he likes with it.
                            >
                            Sucks.
                            >
                            But, if I remove -pedantic, it works still not:
                            >
                            lc -ansic -unused -shadows -O aprog.c
                            Error aprog.c: 14 invalid type specification
                            1 error, 0 warnings
                            1 error
                            >
                            Is signed int short bar = 0; valid C?
                            sure.
                            Q:\>type t.c
                            /*
                            * aprog.c
                            *
                            * "write a program in c."
                            *
                            */
                            #include <stdio.h>
                            #define in "\n"
                            #define c
                            int write(const char *foo)
                            {
                            signed int short bar = 0;
                            const char *baz = foo;
                            while (baz[bar])
                            putchar(bar[baz++]);
                            return 0;
                            }
                            int main(void)
                            {
                            return write("a program" in c);
                            }

                            Q:\>cl /W4 /Ox t.c
                            Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
                            80x86
                            Copyright (C) Microsoft Corporation. All rights reserved.

                            t.c
                            Microsoft (R) Incremental Linker Version 8.00.50727.762
                            Copyright (C) Microsoft Corporation. All rights reserved.

                            /out:t.exe
                            t.obj

                            Q:\>t
                            a program

                            dcorbit@DCORBIT 64 /q
                            $ gcc -W -Wall -ansi -pedantic t.c

                            dcorbit@DCORBIT 64 /q
                            $ ./a
                            a program

                            dcorbit@DCORBIT 64 /q
                            $ gcc --version
                            gcc.exe (GCC) 3.2 (mingw special 20020817-1)
                            Copyright (C) 2002 Free Software Foundation, Inc.
                            This is free software; see the source for copying conditions. There is NO
                            warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


                            dcorbit@DCORBIT 64 /q

                            As you can see from this diagnostic:
                            Q:\>splint t.c
                            Splint 3.1.1 --- 12 Mar 2007

                            t.c: (in function write)
                            t.c(14,12): Test expression for while not boolean, type char: baz[bar]
                            Test expression type is not boolean. (Use -predboolothers to inhibit
                            warning)
                            t.c(15,9): Return value (type int) ignored: putchar(baz++[bar])
                            Result returned by function call is not used. If this is intended, can
                            cast
                            result to (void) to eliminate message. (Use -retvalint to inhibit warning)
                            t.c(10,17): Function exported but not used outside t: write
                            A declaration is exported, but not used outside this module. Declaration
                            can
                            use static qualifier. (Use -exportlocal to inhibit warning)
                            t.c(17,1): Definition of write

                            Finished checking --- 3 code warnings

                            the program relies on an odd feature of the language {as explained in the
                            C-FAQ}:

                            6.11: I came across some "joke" code containing the "expression "
                            5["abcdef"] . How can this be legal C?

                            A: Yes, Virginia, array subscripting is commutative in C. This
                            curious fact follows from the pointer definition of array
                            subscripting, namely that a[e] is identical to *((a)+(e)), for
                            *any* two expressions a and e, as long as one of them is a
                            pointer expression and one is integral. This unsuspected
                            commutativity is often mentioned in C texts as if it were
                            something to be proud of, but it finds no useful application
                            outside of the Obfuscated C Contest (see question 20.36).

                            References: Rationale Sec. 3.3.2.1; H&S Sec. 5.4.1 p. 124,
                            Sec. 7.4.1 pp. 186-7.


                            ** Posted from http://www.teranews.com **

                            Comment

                            • Ben Bacarisse

                              #15
                              Re: need help

                              Hans Schneider <hans@localhost .localdomainwri tes:
                              But, if I remove -pedantic, it works still not:
                              >
                              lc -ansic -unused -shadows -O aprog.c
                              Error aprog.c: 14 invalid type specification
                              1 error, 0 warnings
                              1 error
                              >
                              Is signed int short bar = 0; valid C?
                              Yes -- odd, but valid. <OT>And I get no error from it in lcc-win32.</OT>

                              --
                              Ben.

                              Comment

                              Working...