Redirecting input from file

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

    #46
    Re: Redirecting input from file

    On Jul 4, 9:19 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
    dmora...@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.hNope , Included it.
    (b) you're using C++ Possibly, but don't think so.
    >
    if (a), include it.
    if (b), either
    >
    (d) you're using C++ deliberately Don't think so
    (e) you're using C++ accidentally Possibly
    >
    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
    I won't reply again until I can get to my code. There's really nothing
    I can do or share until then.

    Dave

    Comment

    • dmoran21@cox.net

      #47
      Re: Redirecting input from file

      >
      This is a very strong indication that you are using a C++ compiler and
      not a C compiler.
      That's a good possibility...I 'll have to check the compiler.

      Dave

      Comment

      • Flash Gordon

        #48
        Re: Redirecting input from file

        dmoran21@cox.ne t wrote, On 04/07/07 14:50:
        On Jul 4, 8:08 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
        <snip>
        >--
        >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
        Please do not quote peoples signatures, the bit generally after a "-- ".
        In fact, trim anything not relevant to your reply as I have done.
        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 * *)
        That probably means you are compiling your code as C++ rather than C. To
        find out how to drive the tools you are using ask in a group dedicated
        to your tools or system, but common reasons are using an upper case C as
        the extension instead of a lower case c, using the extension .cpp, or
        having a switch set somewhere to say it is C++. C++ is a significantly
        different language.
        I will post my code tomorrow when I'm in the office.
        Include information about whatever your symptoms are when you do, most
        people don't attempt to remember the problems that are being discussed
        in all the threads. Oh, and make sure you compile as C instead of C++
        before posting anything else.
        --
        Flash Gordon

        Comment

        • CBFalconer

          #49
          Re: Redirecting input from file

          Richard Heathfield wrote:
          >
          .... snip ...
          >
          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. ^^^^^^^^^^
          Are you implying that 1,000,000,000 (or 1e9) casts have been
          generated by programmers since C89 was published? Or are you
          counting multiple use of the same cast, when a program is
          recompiled, copied, etc.? :-)

          --
          <http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
          <http://www.securityfoc us.com/columnists/423>
          <http://www.aaxnet.com/editor/edit043.html>
          cbfalconer at maineline dot net



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

          Comment

          • Barry Schwarz

            #50
            Re: Redirecting input from file

            On Wed, 04 Jul 2007 14:19:10 +0000, Richard Heathfield
            <rjh@see.sig.in validwrote:
            >dmoran21@cox.n et 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>
            Then the message would say "cannot convert int to float*"


            Remove del for email

            Comment

            • Richard Heathfield

              #51
              Re: Redirecting input from file

              Barry Schwarz said:
              On Wed, 04 Jul 2007 14:19:10 +0000, Richard Heathfield wrote:
              >>dmoran21@cox. net said:
              >>
              >>Cannot convert 'void*' to 'float*' in function main(int, char * *)
              >>
              >>Either:
              >>
              >>(a) you forgot to #include <stdlib.h>
              >
              Then the message would say "cannot convert int to float*"
              Oh, well done, sir. Yes, okay, so much for (a).

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

              • Old Wolf

                #52
                Re: Redirecting input from file

                On Jul 4, 7:12 am, "Army1987" <please....@for .itwrote:
                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*).
                In C++ there is an implicit conversion from
                any object pointer type to void*, so there is
                no need to cast any argument to free().

                (Follow-ups set to c.l.c++)

                Comment

                • CBFalconer

                  #53
                  Re: Redirecting input from file

                  Old Wolf wrote:
                  On Jul 4, 7:12 am, "Army1987" <please....@for .itwrote:
                  >
                  >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*).
                  >
                  In C++ there is an implicit conversion from any object pointer type
                  to void*, so there is no need to cast any argument to free().
                  >
                  (Follow-ups set to c.l.c++)
                  Wrong. In C++ there is NO such implicit conversion. That is in C
                  only. Follow-ups set to c.l.c.

                  --
                  <http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
                  <http://www.securityfoc us.com/columnists/423>
                  <http://www.aaxnet.com/editor/edit043.html>
                  cbfalconer at maineline dot net



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

                  Comment

                  • Old Wolf

                    #54
                    Re: Redirecting input from file

                    On Jul 5, 11:26 am, CBFalconer <cbfalco...@yah oo.comwrote:
                    Old Wolf wrote:
                    On Jul 4, 7:12 am, "Army1987" <please....@for .itwrote:
                    >
                    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*).
                    >
                    In C++ there is an implicit conversion from any object pointer
                    type to void*, so there is no need to cast any argument to
                    free().
                    >
                    Wrong. In C++ there is NO such implicit conversion.
                    ISO/IEC 14882:1998, 4.10/2:
                    An rvalue of type "pointer to cv T," where T is an
                    object type, can be converted to an rvalue of type
                    "pointer to cv void." The result of converting a
                    "pointer to cv T" to a "pointer to cv void" points
                    to the start of the storage location where the object
                    of type T resides

                    You must be thinking of something else (perhaps
                    the fact that there's no implicit conversion
                    from void * to other pointer types).
                    That is in C only. Follow-ups set to c.l.c.
                    Not sure why you want to discuss C++ in c.l.c.



                    Comment

                    • Default User

                      #55
                      Re: Redirecting input from file

                      CBFalconer wrote:
                      Old Wolf wrote:
                      In C++ there is an implicit conversion from any object pointer type
                      to void*, so there is no need to cast any argument to free().

                      (Follow-ups set to c.l.c++)
                      >
                      Wrong. In C++ there is NO such implicit conversion. That is in C
                      only. Follow-ups set to c.l.c.

                      Yeah, there is. What's lacking is the implicit conversion from void* to
                      object pointer. Hence malloc() and friends require a cast in C++.




                      Brian

                      Comment

                      • Default User

                        #56
                        Re: Redirecting input from file

                        Old Wolf wrote:

                        In C++ there is an implicit conversion from
                        any object pointer type to void*, so there is
                        no need to cast any argument to free().
                        >
                        (Follow-ups set to c.l.c++)
                        Don't set follow-ups unless when the post wasn't cross there in the
                        first place.



                        Brian

                        Comment

                        • Richard Bos

                          #57
                          Re: Redirecting input from file

                          CBFalconer <cbfalconer@yah oo.comwrote:
                          Richard Heathfield wrote:

                          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. ^^^^^^^^^^
                          >
                          Are you implying that 1,000,000,000 (or 1e9) casts have been
                          generated by programmers since C89 was published? Or are you
                          counting multiple use of the same cast, when a program is
                          recompiled, copied, etc.? :-)
                          No; he's implying that of every 108976 casts written since C89 was
                          published, no more than 10 were The Right Thing. This would mean that
                          0.0091763324034 6...% of casts were right; but since there is only a
                          limited amount of certainty in the starting data, we should clip this
                          to, say, five significant digits, leaving 0.0091763% of right casts, and
                          therefore 99.9908237% wrong ones.

                          I must say, what with the enormous amount of badly written OS code out
                          there, much of it C-wannabe-C++, those figures sound reasonable to me.

                          Richard

                          Comment

                          • dmoran21@cox.net

                            #58
                            Re: Redirecting input from file

                            Here is my code as of now, as well as an input file and my output. I
                            am aware that I've got more error proofing to do, but this is what I
                            have right now.

                            #include <stdio.h>
                            #include <stdlib.h>

                            int main(int argc, char *argv[])
                            {
                            /* Variable Declarations */
                            const int arraylength = 5000;
                            const int exiterrorcode = -1;
                            int count = 0;
                            int condition = 1;
                            float* precipvals = (float*)NULL;
                            float* precip3hrs = (float*)NULL;
                            long* date = (long*)NULL;
                            FILE *fpin;
                            FILE *fpout;

                            fpin = fopen(argv[1],"r");
                            fpout = fopen(argv[2],"w");

                            if(fpin == NULL || fpout == NULL) {
                            printf("Insuffi cient arguments\n");
                            exit(exiterrorc ode);
                            }

                            /* Array Allocation */
                            precipvals = (float*)malloc( sizeof(float) * arraylength);
                            precip3hrs = (float*)malloc( sizeof(float) * arraylength);
                            date = (long*)malloc(s izeof(long) * arraylength);

                            /* Calculation Section */
                            while(condition != EOF) {
                            condition = fscanf(fpin,"%l d,%f", &date[count],
                            &precipvals[count]);
                            if(count == 0) {
                            precip3hrs[count] = precipvals[count];
                            }
                            if(count == 1) {
                            precip3hrs[count] = precipvals[count] + precip3hrs[count-1];
                            }
                            if(count 1) {
                            precip3hrs[count] = precipvals[count] + precipvals[count-1] +
                            precipvals[count-2];
                            }
                            count++;
                            }

                            /* Output section */
                            for(count = 0; count < arraylength; count++) {
                            if(!(precipvals[count] == 0 && precip3hrs[count] == 0)) {
                            if(count == 0) {
                            printf("One hour precipitation: %2.2f Three hour precipitation
                            %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            if(count == 1) {
                            printf("One hour precipitation: %2.2f Three hour precipitation
                            %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            if(count 1) {
                            printf("One hour precipitation: %2.2f Three hour precipitation
                            %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            }
                            }


                            /* Write to file */
                            for(count = 0; count < arraylength; count++) {
                            if(!(precipvals[count] == 0 && precip3hrs[count] == 0)) {
                            if(count == 0) {
                            fprintf(fpout," One hour precipitation: %2.2f Three hour
                            precipitation %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            if(count == 1) {
                            fprintf(fpout, "One hour precipitation: %2.2f Three hour
                            precipitation %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            if(count 1) {
                            fprintf(fpout, "One hour precipitation: %2.2f Three hour
                            precipitation %2.2f\n",precip vals[count],precip3hrs[count]);
                            }
                            }
                            }

                            fclose(fpin);
                            fclose(fpout);

                            /* Deallocation */
                            free(precipvals );
                            precipvals = (float*)NULL;
                            free(precip3hrs );
                            precip3hrs = (float*)NULL;
                            date = (long*)NULL;
                            free(date);

                            return 0;
                            }

                            Input file
                            200701010000,3. 58
                            200701010100,2. 33
                            200701010200,4. 55
                            200701010300,.2 9
                            200701010400,5. 18
                            200701010500,0
                            200701010600,0
                            200701010700,0
                            200701010800,0
                            200701010900,.3 4

                            Output file
                            One hour precipitation: 3.58 Three hour precipitation 3.58
                            One hour precipitation: 2.33 Three hour precipitation 5.91
                            One hour precipitation: 4.55 Three hour precipitation 10.46
                            One hour precipitation: 0.29 Three hour precipitation 7.17
                            One hour precipitation: 5.18 Three hour precipitation 10.02
                            One hour precipitation: 0.00 Three hour precipitation 5.47
                            One hour precipitation: 0.00 Three hour precipitation 5.18
                            One hour precipitation: 0.34 Three hour precipitation 0.34
                            One hour precipitation: 0.00 Three hour precipitation 0.34

                            TIA
                            Dave

                            Comment

                            • dmoran21@cox.net

                              #59
                              Re: Redirecting input from file

                              Now that I look at the code some more, I think there's a few areas
                              that I can remove i.e if(count = 0) etc. but I'm not sure.

                              Dave

                              Comment

                              • CBFalconer

                                #60
                                Re: Redirecting input from file

                                "dmoran21@cox.n et" wrote:
                                >
                                Here is my code as of now, as well as an input file and my output.
                                I am aware that I've got more error proofing to do, but this is
                                what I have right now.
                                >
                                #include <stdio.h>
                                #include <stdlib.h>
                                >
                                int main(int argc, char *argv[])
                                {
                                /* Variable Declarations */
                                To start with, control your indentation. 3 spaces is enough.
                                Don't use tabs for Usenet display.
                                const int arraylength = 5000;
                                const int exiterrorcode = -1;
                                int count = 0;
                                int condition = 1;
                                float* precipvals = (float*)NULL;
                                float* precip3hrs = (float*)NULL;
                                long* date = (long*)NULL;
                                The above casts are unnecessary, and only serve to hide possible
                                errors. This is not C++.
                                FILE *fpin;
                                FILE *fpout;
                                >
                                fpin = fopen(argv[1],"r");
                                fpout = fopen(argv[2],"w");
                                >
                                if(fpin == NULL || fpout == NULL) {
                                printf("Insuffi cient arguments\n");
                                exit(exiterrorc ode);
                                }
                                I believe passing NULL to fopen results in undefined behaviour.
                                Use argc.
                                >
                                /* Array Allocation */
                                precipvals = (float*)malloc( sizeof(float) * arraylength);
                                precip3hrs = (float*)malloc( sizeof(float) * arraylength);
                                date = (long*)malloc(s izeof(long) * arraylength);
                                Again, the casts are unnecessary etc.
                                >
                                /* Calculation Section */
                                while(condition != EOF) {
                                condition = fscanf(fpin,"%l d,%f", &date[count],
                                &precipvals[count]);
                                Here unless 'condition' is 2 fscanf failed. I also gave up
                                following the code.

                                --
                                <http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
                                <http://www.securityfoc us.com/columnists/423>
                                <http://www.aaxnet.com/editor/edit043.html>
                                cbfalconer at maineline dot net



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

                                Comment

                                Working...