Redirecting input from file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dmoran21@cox.net

    #31
    Re: Redirecting input from file

    On Jul 3, 2:12 pm, "Army1987" <please....@for .itwrote:
    <dmora...@cox.n etha scritto nel messaggionews:1 183473735.07644 0.202070@k29g20 00hsd.googlegro ups.com...
    [snip code which casts the result of malloc]I also tried to remove the casts and it didn't run.
    >
    Are you compiling it with a C++ compiler?
    (If so, I'd be surprised of knowing free() works even without
    casting the argument to void*).
    I am compiling with gcc on Linux. As for the results of the runs, my
    boss ran the program that I wrote and the output looks like it's OK. I
    will admit that I've not dealt with arrays since I took a class in C
    in 2004. I still have my notes and books from that class and just did
    it the way the book and notes told me. The notes are also online at
    cs1313.ou.edu if you want to check them out.

    Dave

    Comment

    • Keith Thompson

      #32
      Re: Redirecting input from file

      "dmoran21@cox.n et" <dmoran21@cox.n etwrites:
      On Jul 3, 2:12 pm, "Army1987" <please....@for .itwrote:
      ><dmora...@cox. netha scritto nel
      >messaggionews: 1183473735.0764 40.202070@k29g2 000hsd.googlegr oups.com...
      >[snip code which casts the result of malloc]
      I also tried to remove the casts and it didn't run.
      >>
      >Are you compiling it with a C++ compiler?
      >(If so, I'd be surprised of knowing free() works even without
      >casting the argument to void*).
      >
      I am compiling with gcc on Linux. As for the results of the runs, my
      boss ran the program that I wrote and the output looks like it's OK. I
      will admit that I've not dealt with arrays since I took a class in C
      in 2004. I still have my notes and books from that class and just did
      it the way the book and notes told me. The notes are also online at
      cs1313.ou.edu if you want to check them out.
      If you have code that casts the result of malloc, and removing the
      cast causes it to fail, the most likely explanation is that you've
      forgetten the required '#include <stdlib.h>'.

      Telling us that "it didn't run" doesn't help anybody. You keep
      telling us things that make it clear that there are problems in your
      code, but you don't post the actual code so we can help you fix them.

      You can post your actual current code and let us help you with it, or
      you can keep it to yourself and rest secure in the knowledge that your
      code will continue to work until it breaks at the most inconvenient
      possible moment. It's your choice.

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

      Comment

      • dmoran21@cox.net

        #33
        Re: Redirecting input from file

        On Jul 3, 7:22 pm, Keith Thompson <k...@mib.orgwr ote:
        "dmora...@cox.n et" <dmora...@cox.n etwrites:
        On Jul 3, 2:12 pm, "Army1987" <please....@for .itwrote:
        <dmora...@cox.n etha scritto nel
        messaggionews:1 183473735.07644 0.202070@k29g20 00hsd.googlegro ups.com...
        [snip code which casts the result of malloc]
        I also tried to remove the casts and it didn't run.
        >
        Are you compiling it with a C++ compiler?
        (If so, I'd be surprised of knowing free() works even without
        casting the argument to void*).
        >
        I am compiling with gcc on Linux. As for the results of the runs, my
        boss ran the program that I wrote and the output looks like it's OK. I
        will admit that I've not dealt with arrays since I took a class in C
        in 2004. I still have my notes and books from that class and just did
        it the way the book and notes told me. The notes are also online at
        cs1313.ou.edu if you want to check them out.
        >
        If you have code that casts the result of malloc, and removing the
        cast causes it to fail, the most likely explanation is that you've
        forgetten the required '#include <stdlib.h>'.
        >
        Telling us that "it didn't run" doesn't help anybody. You keep
        telling us things that make it clear that there are problems in your
        code, but you don't post the actual code so we can help you fix them.
        >
        You can post your actual current code and let us help you with it, or
        you can keep it to yourself and rest secure in the knowledge that your
        code will continue to work until it breaks at the most inconvenient
        possible moment. It's your choice.
        >
        --
        Keith Thompson (The_Other_Keit h) k...@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"
        I will post the code when I have it up at work...I can't get to it at
        home.

        Dave

        Comment

        • Ben Bacarisse

          #34
          Re: Redirecting input from file

          "dmoran21@cox.n et" <dmoran21@cox.n etwrites:
          <snip>
          I still have my notes and books from that class and just did
          it the way the book and notes told me. The notes are also online at
          cs1313.ou.edu if you want to check them out.
          A rather depressing density of errors. OK, it is a course for non CS
          students but even so... I was going to pick out some of my favourite
          howlers but, after a little thought, that seems rather cruel.

          --
          Ben.

          Comment

          • dmoran21@cox.net

            #35
            Re: Redirecting input from file

            On Jul 3, 7:43 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
            "dmora...@cox.n et" <dmora...@cox.n etwrites:
            >
            <snip>
            >
            I still have my notes and books from that class and just did
            it the way the book and notes told me. The notes are also online at
            cs1313.ou.edu if you want to check them out.
            >
            A rather depressing density of errors. OK, it is a course for non CS
            students but even so... I was going to pick out some of my favourite
            howlers but, after a little thought, that seems rather cruel.
            >
            --
            Ben.
            When I took the class, it was required to do things a certain way and
            that's the way I've always done them because I've only learned that
            way. Maybe I need to go buy another book.

            Dave

            Comment

            • Barry Schwarz

              #36
              Re: Redirecting input from file

              On Tue, 03 Jul 2007 06:42:01 -0700, "dmoran21@cox.n et"
              <dmoran21@cox.n etwrote:
              >On Jul 2, 2:07 pm, "Army1987" <please....@for .itwrote:
              Many relevant comments the OP chose to ignore.
              ><dmora...@cox. netha scritto nel messaggionews:1 183391088.90249 9.192290@n60g20 00hse.googlegro ups.com...I've got one more error that I can't seem to get worked out. I have a
              segmentation fault and upon playing with my code, I think that it
              crashes when I try to deallocate the "date" array.
              snip
              #include <math.h>
              If your book tells you to include unused headers ...
              >>
              snip
              float* precipvals = (float*)NULL;
              and to cast the NULL pointer constant ...
              float* precip3hrs = (float*)NULL;
              snip
              precipvals = (float*)malloc( sizeof(int) * arraylength);
              and to cast the return from malloc ...

              and that sizeof(int) is enough space for a float ...
              >>
              snip
              >I'm just going by the way I was taught and how my book does it. I'm
              >not a professional programmer.
              then you very much need to find a better book.



              Remove del for email

              Comment

              • dmoran21@cox.net

                #37
                Re: Redirecting input from file

                then you very much need to find a better book.
                >
                Remove del for email
                I included the math.h header because I originally planned to do some
                other calculations, but forgot to take it out when I changed my mind.

                Dave

                Comment

                • Richard Heathfield

                  #38
                  Re: Redirecting input from file

                  Ben Bacarisse said:
                  "dmoran21@cox.n et" <dmoran21@cox.n etwrites:
                  <snip>
                  >I still have my notes and books from that class and just did
                  >it the way the book and notes told me. The notes are also online at
                  >cs1313.ou.ed u if you want to check them out.
                  >
                  A rather depressing density of errors. OK, it is a course for non CS
                  students but even so... I was going to pick out some of my favourite
                  howlers but, after a little thought, that seems rather cruel.
                  I looked at two of the PDFs (the intro, and the one on variables), and
                  found little that was actually wrong. Presumably it gets worse later
                  on.

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

                  Comment

                  • Flash Gordon

                    #39
                    Re: Redirecting input from file

                    dmoran21@cox.ne t wrote, On 04/07/07 02:18:
                    On Jul 3, 7:43 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
                    >"dmora...@cox. net" <dmora...@cox.n etwrites:
                    >>
                    ><snip>
                    >>
                    >>I still have my notes and books from that class and just did
                    >>it the way the book and notes told me. The notes are also online at
                    >>cs1313.ou.e du if you want to check them out.
                    >A rather depressing density of errors. OK, it is a course for non CS
                    >students but even so... I was going to pick out some of my favourite
                    >howlers but, after a little thought, that seems rather cruel.
                    >
                    When I took the class, it was required to do things a certain way and
                    that's the way I've always done them because I've only learned that
                    way. Maybe I need to go buy another book.
                    I've not looked at the notes, but I would recommend K&R2 as a reference
                    whatever your current book is.
                    --
                    Flash Gordon

                    Comment

                    • Army1987

                      #40
                      Re: Redirecting input from file


                      "Keith Thompson" <kst-u@mib.orgha scritto nel messaggio news:lnsl8510hr .fsf@nuthaus.mi b.org...
                      "dmoran21@cox.n et" <dmoran21@cox.n etwrites:
                      >On Jul 3, 2:12 pm, "Army1987" <please....@for .itwrote:
                      >><dmora...@cox .netha scritto nel
                      >>messaggionews :1183473735.076 440.202070@k29g 2000hsd.googleg roups.com...
                      >>[snip code which casts the result of malloc]
                      >I also tried to remove the casts and it didn't run.
                      >>>
                      >>Are you compiling it with a C++ compiler?
                      >>(If so, I'd be surprised of knowing free() works even without
                      >>casting the argument to void*).
                      >>
                      >I am compiling with gcc on Linux. As for the results of the runs, my
                      >boss ran the program that I wrote and the output looks like it's OK. I
                      >will admit that I've not dealt with arrays since I took a class in C
                      >in 2004. I still have my notes and books from that class and just did
                      >it the way the book and notes told me. The notes are also online at
                      >cs1313.ou.ed u if you want to check them out.
                      >
                      If you have code that casts the result of malloc, and removing the
                      cast causes it to fail, the most likely explanation is that you've
                      forgetten the required '#include <stdlib.h>'.
                      He did include it, at least in the code he posted.


                      Comment

                      • dmoran21@cox.net

                        #41
                        Re: Redirecting input from file

                        On Jul 4, 1:31 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                        Ben Bacarisse said:
                        >
                        "dmora...@cox.n et" <dmora...@cox.n etwrites:
                        <snip>
                        I still have my notes and books from that class and just did
                        it the way the book and notes told me. The notes are also online at
                        cs1313.ou.edu if you want to check them out.
                        >
                        A rather depressing density of errors. OK, it is a course for non CS
                        students but even so... I was going to pick out some of my favourite
                        howlers but, after a little thought, that seems rather cruel.
                        >
                        I looked at two of the PDFs (the intro, and the one on variables), and
                        found little that was actually wrong. Presumably it gets worse later
                        on.
                        >
                        --
                        Richard Heathfield <http://www.cpax.org.uk >
                        Email: -www. +rjh@
                        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                        "Usenet is a strange place" - dmr 29 July 1999
                        The book I have is called "C: How To Program" by Deitel and Deitel.
                        Perhaps C isn't the best language to learn for my profession. I am a
                        professional Mathematician and going back to school to finish my
                        meteorology degree.

                        Dave

                        Comment

                        • Richard Heathfield

                          #42
                          Re: Redirecting input from file

                          dmoran21@cox.ne t said:

                          <snip>
                          The book I have is called "C: How To Program" by Deitel and Deitel.
                          Well, that's okay. Not perfect, but pretty good.
                          Perhaps C isn't the best language to learn for my profession.
                          Oh, C is always the best language to learn, no matter what your
                          profession. Whether you're a truck driver or a ballroom dancer or a
                          hypnotherapist or a wheeltapper, C is what you want.
                          I am a
                          professional Mathematician and going back to school to finish my
                          meteorology degree.
                          Sounds like a job for C and possibly Matlab.

                          Drop all those silly casts. If that gives you diagnostic messages at
                          compile time or breaks the behaviour at runtime, *tell us*, and we'll
                          show you how to fix it. 99.9908237% of the time, casts aren't the right
                          fix.

                          Whenever you attempt to acquire a resource (either open a file, or
                          allocate memory, or whatever it is), check that the attempt succeeded.

                          I fixed your code along these lines recently. As far as I can tell, you
                          ignored those fixes. I'm still waiting for evidence of willingness to
                          learn before I expend more debugging time here.

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

                          Comment

                          • dmoran21@cox.net

                            #43
                            Re: Redirecting input from file

                            On Jul 4, 8:08 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                            dmora...@cox.ne t said:
                            >
                            <snip>
                            >
                            The book I have is called "C: How To Program" by Deitel and Deitel.
                            >
                            Well, that's okay. Not perfect, but pretty good.
                            >
                            Perhaps C isn't the best language to learn for my profession.
                            >
                            Oh, C is always the best language to learn, no matter what your
                            profession. Whether you're a truck driver or a ballroom dancer or a
                            hypnotherapist or a wheeltapper, C is what you want.
                            >
                            I am a
                            professional Mathematician and going back to school to finish my
                            meteorology degree.
                            >
                            Sounds like a job for C and possibly Matlab.
                            >
                            Drop all those silly casts. If that gives you diagnostic messages at
                            compile time or breaks the behaviour at runtime, *tell us*, and we'll
                            show you how to fix it. 99.9908237% of the time, casts aren't the right
                            fix.
                            >
                            Whenever you attempt to acquire a resource (either open a file, or
                            allocate memory, or whatever it is), check that the attempt succeeded.
                            >
                            I fixed your code along these lines recently. As far as I can tell, you
                            ignored those fixes. I'm still waiting for evidence of willingness to
                            learn before I expend more debugging time here.
                            >
                            --
                            Richard Heathfield <http://www.cpax.org.uk >
                            Email: -www. +rjh@
                            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                            "Usenet is a strange place" - dmr 29 July 1999
                            I got my hands on the error messages that I got (I got into my e-mail
                            at work, but since I'm not in the office today, I can't get to my
                            code). I got the following:

                            Cannot convert 'void*' to 'float*' in function main(int, char * *)

                            I will post my code tomorrow when I'm in the office.

                            Dave

                            Comment

                            • Barry Schwarz

                              #44
                              Re: Redirecting input from file

                              On Wed, 04 Jul 2007 06:50:40 -0700, "dmoran21@cox.n et"
                              <dmoran21@cox.n etwrote:
                              >On Jul 4, 8:08 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
                              >dmora...@cox.n et said:
                              >>
                              ><snip>
                              >>
                              The book I have is called "C: How To Program" by Deitel and Deitel.
                              >>
                              >Well, that's okay. Not perfect, but pretty good.
                              >>
                              Perhaps C isn't the best language to learn for my profession.
                              >>
                              >Oh, C is always the best language to learn, no matter what your
                              >profession. Whether you're a truck driver or a ballroom dancer or a
                              >hypnotherapi st or a wheeltapper, C is what you want.
                              >>
                              I am a
                              professional Mathematician and going back to school to finish my
                              meteorology degree.
                              >>
                              >Sounds like a job for C and possibly Matlab.
                              >>
                              >Drop all those silly casts. If that gives you diagnostic messages at
                              >compile time or breaks the behaviour at runtime, *tell us*, and we'll
                              >show you how to fix it. 99.9908237% of the time, casts aren't the right
                              >fix.
                              >>
                              >Whenever you attempt to acquire a resource (either open a file, or
                              >allocate memory, or whatever it is), check that the attempt succeeded.
                              >>
                              >I fixed your code along these lines recently. As far as I can tell, you
                              >ignored those fixes. I'm still waiting for evidence of willingness to
                              >learn before I expend more debugging time here.
                              >>
                              >--
                              >Richard Heathfield <http://www.cpax.org.uk >
                              >Email: -www. +rjh@
                              >Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                              >"Usenet is a strange place" - dmr 29 July 1999
                              >
                              >I got my hands on the error messages that I got (I got into my e-mail
                              >at work, but since I'm not in the office today, I can't get to my
                              >code). I got the following:
                              >
                              >Cannot convert 'void*' to 'float*' in function main(int, char * *)
                              This is a very strong indication that you are using a C++ compiler and
                              not a C compiler.


                              Remove del for email

                              Comment

                              • Richard Heathfield

                                #45
                                Re: Redirecting input from file

                                dmoran21@cox.ne t said:

                                <snip>
                                I got my hands on the error messages that I got (I got into my e-mail
                                at work, but since I'm not in the office today, I can't get to my
                                code). I got the following:
                                >
                                Cannot convert 'void*' to 'float*' in function main(int, char * *)
                                Either:

                                (a) you forgot to #include <stdlib.h>
                                (b) you're using C++

                                if (a), include it.
                                if (b), either

                                (d) you're using C++ deliberately
                                (e) you're using C++ accidentally

                                if (d), ask in comp.lang.c++ rather than comp.lang.c
                                if (e), you may find that changing your filename suffix from .cpp to .c
                                is sufficient.

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

                                Comment

                                Working...