k&r2

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

    #1

    k&r2

    I copied this code from page 9 k&r 2 and it gives an error that even I
    can see. Celsius is uninialized.

    /* code */

    #include <stdio.h>

    main(){
    int fahr,celsius,lo wer,upper,step;
    lower=0;
    upper=300;
    step=20;
    fahr=lower;
    while (fahr<=upper)
    {celsius=5*(fah r-32)/9;
    printf("%d\t%d\ n",fahr,celsuis ;
    fahr=farh+step; }}

    /*end*/

    Celsius is intialized within the body of the while function. Why is this
    code from k&r2 not working?

    Bill


  • Walter Roberson

    #2
    Re: k&amp;r2

    In article <b9l2j.29168$Xg .23657@trnddc06 >,
    Bill Cunningham <some@net.comwr ote:
    I copied this code from page 9 k&r 2 and it gives an error that even I
    >can see. Celsius is uninialized.
    >/* code */
    >#include <stdio.h>
    >
    >main(){
    int fahr,celsius,lo wer,upper,step;
    lower=0;
    upper=300;
    step=20;
    fahr=lower;
    while (fahr<=upper)
    {celsius=5*(fah r-32)/9;
    printf("%d\t%d\ n",fahr,celsuis ;
    Did you notice the misspelling of celsius on the above line?
    fahr=farh+step; }}
    >
    >/*end*/
    --
    "No one has the right to destroy another person's belief by
    demanding empirical evidence." -- Ann Landers

    Comment

    • Marco Manfredini

      #3
      Re: k&amp;r2

      Bill Cunningham wrote:
      I copied this code from page 9 k&r 2 and it gives an error that even I
      can see. Celsius is uninialized.
      >
      /* code */
      >
      #include <stdio.h>
      >
      main(){
      int fahr,celsius,lo wer,upper,step;
      lower=0;
      upper=300;
      step=20;
      fahr=lower;
      while (fahr<=upper)
      {celsius=5*(fah r-32)/9;
      printf("%d\t%d\ n",fahr,celsuis ;
      fahr=farh+step; }}
      >
      /*end*/
      >
      Celsius is intialized within the body of the while function. Why is this
      code from k&r2 not working?
      You should read the message again. Isn't it rather "celsuis is
      undefined"? celsuis?

      And did you get something about "farh"?

      Comment

      • Bill Cunningham

        #4
        Re: k&amp;r2


        "Walter Roberson" <roberson@ibd.n rc-cnrc.gc.cawrote in message
        news:ficn3p$4rh $1@canopus.cc.u manitoba.ca...
        In article <b9l2j.29168$Xg .23657@trnddc06 >,
        Bill Cunningham <some@net.comwr ote:
        > I copied this code from page 9 k&r 2 and it gives an error that even I
        >>can see. Celsius is uninialized.
        >
        >>/* code */
        >
        >>#include <stdio.h>
        >>
        >>main(){
        > int fahr,celsius,lo wer,upper,step;
        > lower=0;
        > upper=300;
        > step=20;
        > fahr=lower;
        > while (fahr<=upper)
        > {celsius=5*(fah r-32)/9;
        > printf("%d\t%d\ n",fahr,celsuis ;
        >
        Did you notice the misspelling of celsius on the above line?
        No. My mistake then. :(
        >
        > fahr=farh+step; }}
        >>
        >>/*end*/

        Comment

        • CBFalconer

          #5
          Re: k&amp;r2

          Bill Cunningham wrote:
          >
          I copied this code from page 9 k&r 2 and it gives an error that
          even I can see. Celsius is uninialized.
          >
          /* code */
          >
          #include <stdio.h>
          >
          main(){
          int fahr,celsius,lo wer,upper,step;
          lower=0;
          upper=300;
          step=20;
          fahr=lower;
          while (fahr<=upper)
          {celsius=5*(fah r-32)/9;
          printf("%d\t%d\ n",fahr,celsuis ;
          fahr=farh+step; }}
          >
          /*end*/
          >
          Celsius is intialized within the body of the while function. Why
          is this code from k&r2 not working?
          Because that is not the code from K&R.

          --
          Chuck F (cbfalconer at maineline dot net)
          <http://cbfalconer.home .att.net>
          Try the download section.


          --
          Posted via a free Usenet account from http://www.teranews.com

          Comment

          • J. J. Farrell

            #6
            Re: k&amp;r2

            Bill Cunningham wrote:
            I copied this code from page 9 k&r 2 and it gives an error that even I
            can see. Celsius is uninialized.
            >
            /* code */
            >
            #include <stdio.h>
            >
            main(){
            int fahr,celsius,lo wer,upper,step;
            lower=0;
            upper=300;
            step=20;
            fahr=lower;
            while (fahr<=upper)
            {celsius=5*(fah r-32)/9;
            printf("%d\t%d\ n",fahr,celsuis ;
            fahr=farh+step; }}
            >
            /*end*/
            >
            Celsius is intialized within the body of the while function. Why is this
            code from k&r2 not working?
            Most likely because of various typos which make it very different from
            the code in K&R2.

            Comment

            • Joe Wright

              #7
              Re: k&amp;r2

              Bill Cunningham wrote:
              I copied this code from page 9 k&r 2 and it gives an error that even I
              can see. Celsius is uninialized.
              >
              /* code */
              >
              #include <stdio.h>
              >
              main(){
              int fahr,celsius,lo wer,upper,step;
              lower=0;
              upper=300;
              step=20;
              fahr=lower;
              while (fahr<=upper)
              {celsius=5*(fah r-32)/9;
              printf("%d\t%d\ n",fahr,celsuis ;
              fahr=farh+step; }}
              >
              /*end*/
              >
              Celsius is intialized within the body of the while function. Why is this
              code from k&r2 not working?
              >
              Bill
              >
              >
              Mine works..

              #include <stdio.h>

              int main(void)
              {
              int fahr, celcius;
              int lower, upper, step;

              lower = 0;
              upper = 300;
              step = 20;

              fahr = lower;
              while (fahr <= upper) {
              celcius = 5 * (fahr - 32) / 9;
              printf("%d\t%d\ n", fahr, celcius);
              fahr = fahr + step;
              }
              return 0;
              }

              --
              Joe Wright
              "Everything should be made as simple as possible, but not simpler."
              --- Albert Einstein ---

              Comment

              • TerryP

                #8
                Re: k&amp;r2

                Bill Cunningham wrote:
                >> {celsius=5*(fah r-32)/9;
                >> printf("%d\t%d\ n",fahr,celsuis ;
                >>
                >Did you notice the misspelling of celsius on the above line?
                >
                No. My mistake then. :(
                The Typo, the bane of compilation!

                I remember I once spent 2 hours trying to find the problem in a program (of
                mine) that failed to build, some times I wish they made a compiler that gave
                errors like:

                file:line !!! PEBKAC !!!
                sp,member != sp.member -- you are a blind idiot,

                After finally finding out that I had been working to long to notice the
                difference between , and . I decided to get a better font xD

                --
                no brainer:
                A decision which, viewed through the retrospectoscop e,
                is "obvious" to those who failed to make it originally.

                Comment

                • Martin Ambuhl

                  #9
                  Re: k&amp;r2

                  Bill Cunningham wrote:
                  I copied this code from page 9 k&r 2 and it gives an error that even I
                  can see. Celsius is uninialized.
                  It has a value assigned before use, so what's the problem?
                  [...]
                  int fahr,celsius,lo wer,upper,step;
                  [...]
                  while (fahr<=upper)
                  {celsius=5*(fah r-32)/9;
                  [...]
                  Why is this
                  code from k&r2 not working?
                  Is this really the code from K&R2? If it is, perhaps we should retreat
                  to K&R1, where these lines are
                  while )fahr <= upper) {
                  celsius = (5.0/9.0) * (fahr-32.0);

                  Comment

                  • Joachim Schmitz

                    #10
                    Re: k&amp;r2

                    "CBFalconer " <cbfalconer@yah oo.comschrieb im Newsbeitrag
                    news:4749F6CE.B 79E4735@yahoo.c om...
                    Bill Cunningham wrote:
                    >>
                    >I copied this code from page 9 k&r 2 and it gives an error that
                    >even I can see. Celsius is uninialized.
                    >>
                    >/* code */
                    >>
                    >#include <stdio.h>
                    >>
                    >main(){
                    > int fahr,celsius,lo wer,upper,step;
                    > lower=0;
                    > upper=300;
                    > step=20;
                    > fahr=lower;
                    > while (fahr<=upper)
                    > {celsius=5*(fah r-32)/9;
                    > printf("%d\t%d\ n",fahr,celsuis ;
                    > fahr=farh+step; }}
                    >>
                    >/*end*/
                    >>
                    >Celsius is intialized within the body of the while function. Why
                    >is this code from k&r2 not working?
                    >
                    Because that is not the code from K&R.
                    Very helpful answer 8-(
                    Fortunatly others had been far more helpfull in pointing out the typo(s)

                    Bye, Jojo


                    Comment

                    • Joachim Schmitz

                      #11
                      Re: k&amp;r2

                      "Martin Ambuhl" <mambuhl@earthl ink.netschrieb im Newsbeitrag
                      news:5qv56aF11u 6miU1@mid.indiv idual.net...
                      Bill Cunningham wrote:
                      > I copied this code from page 9 k&r 2 and it gives an error that even
                      >I can see. Celsius is uninialized.
                      It has a value assigned before use, so what's the problem?
                      [...]
                      int fahr,celsius,lo wer,upper,step;
                      [...]
                      > while (fahr<=upper)
                      > {celsius=5*(fah r-32)/9;
                      [...]
                      >Why is this code from k&r2 not working?
                      >
                      Is this really the code from K&R2? If it is, perhaps we should retreat to
                      K&R1, where these lines are
                      while )fahr <= upper) {
                      celsius = (5.0/9.0) * (fahr-32.0);
                      Really? Does K&R1 have such bad typos?

                      After correction it gives a warning:
                      implicit conversion from "double" to "int": rounding, sign extension, or
                      loss of accuracy may result

                      Bye, Jojo


                      Comment

                      • Joachim Schmitz

                        #12
                        Re: k&amp;r2

                        "Joe Wright" <joewwright@com cast.netschrieb im Newsbeitrag
                        news:27SdnaWFpZ vgp9fanZ2dnUVZ_ hudnZ2d@comcast .com...
                        Bill Cunningham wrote:
                        > I copied this code from page 9 k&r 2 and it gives an error that even
                        >I can see. Celsius is uninialized.
                        >>
                        >/* code */
                        >>
                        >#include <stdio.h>
                        >>
                        >main(){
                        > int fahr,celsius,lo wer,upper,step;
                        > lower=0;
                        > upper=300;
                        > step=20;
                        > fahr=lower;
                        > while (fahr<=upper)
                        > {celsius=5*(fah r-32)/9;
                        > printf("%d\t%d\ n",fahr,celsuis ;
                        > fahr=farh+step; }}
                        >>
                        >/*end*/
                        >>
                        >Celsius is intialized within the body of the while function. Why is this
                        >code from k&r2 not working?
                        >>
                        >Bill
                        >>
                        >>
                        Mine works..
                        >
                        #include <stdio.h>
                        >
                        int main(void)
                        {
                        int fahr, celcius;
                        int lower, upper, step;
                        >
                        lower = 0;
                        upper = 300;
                        step = 20;
                        >
                        fahr = lower;
                        while (fahr <= upper) {
                        celcius = 5 * (fahr - 32) / 9;
                        printf("%d\t%d\ n", fahr, celcius);
                        fahr = fahr + step;
                        }
                        return 0;
                        }
                        Your code might work, but it too misspells celsius.

                        Bye, Jojo

                        PS: This is something I notice immediatelly, because Celsius(weg) is the
                        street I live at... If I have to spell Celsius I usually refer to
                        Fahrenheit, once with the result that it got spelled "Felsius" 8-)


                        Comment

                        • Martin Ambuhl

                          #13
                          Re: k&amp;r2

                          Joachim Schmitz wrote:
                          "Martin Ambuhl" <mambuhl@earthl ink.netschrieb im Newsbeitrag
                          news:5qv56aF11u 6miU1@mid.indiv idual.net...
                          >Bill Cunningham wrote:
                          >> I copied this code from page 9 k&r 2 and it gives an error that even
                          >>I can see. Celsius is uninialized.
                          > It has a value assigned before use, so what's the problem?
                          >[...]
                          > int fahr,celsius,lo wer,upper,step;
                          >[...]
                          >> while (fahr<=upper)
                          >> {celsius=5*(fah r-32)/9;
                          >[...]
                          >>Why is this code from k&r2 not working?
                          >Is this really the code from K&R2? If it is, perhaps we should retreat to
                          >K&R1, where these lines are
                          > while )fahr <= upper) {
                          > celsius = (5.0/9.0) * (fahr-32.0);
                          Really? Does K&R1 have such bad typos?
                          No, that's my typo (and unless I missing something, that is properly
                          singular).
                          >
                          After correction it gives a warning:
                          implicit conversion from "double" to "int": rounding, sign extension, or
                          loss of accuracy may result
                          While your implementation is free to issue such warnings, they are
                          hardly required. People with a mania for compiles without warnings
                          might take this is an indication that they should "fix" the code with a
                          useless cast. Since casts to "shut the compiler up" are all too
                          frequently a bad idea, I'm not so sure that the warning is a good idea.

                          Comment

                          • santosh

                            #14
                            Re: k&amp;r2

                            In article <fidsvi$1gj$1@o nline.de>, Joachim Schmitz
                            <nospam.jojo@sc hmitz-digital.dewrote on Monday 26 Nov 2007 1:05 pm:
                            "Martin Ambuhl" <mambuhl@earthl ink.netschrieb im Newsbeitrag
                            news:5qv56aF11u 6miU1@mid.indiv idual.net...
                            >Bill Cunningham wrote:
                            >> I copied this code from page 9 k&r 2 and it gives an error that
                            >> even
                            >>I can see. Celsius is uninialized.
                            > It has a value assigned before use, so what's the problem?
                            >[...]
                            > int fahr,celsius,lo wer,upper,step;
                            >[...]
                            >> while (fahr<=upper)
                            >> {celsius=5*(fah r-32)/9;
                            >[...]
                            >>Why is this code from k&r2 not working?
                            >>
                            >Is this really the code from K&R2? If it is, perhaps we should
                            >retreat to K&R1, where these lines are
                            > while )fahr <= upper) {
                            > celsius = (5.0/9.0) * (fahr-32.0);
                            Really? Does K&R1 have such bad typos?
                            >
                            After correction it gives a warning:
                            implicit conversion from "double" to "int": rounding, sign extension,
                            or loss of accuracy may result
                            I could be wrong but, depending on the value in 'fahr', that statement
                            might invoke undefined behaviour.

                            Comment

                            • Richard Heathfield

                              #15
                              Re: k&amp;r2

                              Joachim Schmitz said:
                              "Joe Wright" <joewwright@com cast.netschrieb im Newsbeitrag
                              <snip>
                              > printf("%d\t%d\ n", fahr, celcius);
                              > fahr = fahr + step;
                              > }
                              > return 0;
                              >}
                              Your code might work, but it too misspells celsius.
                              >
                              Bye, Jojo
                              >
                              PS: This is something I notice immediatelly,
                              I note that your spelling flame contains a spelling error. It's
                              heart-warming to see the old traditions being maintained. :-)

                              --
                              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

                              Working...