sh?tpile of errors

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

    #16
    Re: sh?tpile of errors


    "Martin Ambuhl" <mambuhl@earthl ink.netwrote in message
    news:TIGdnRoOIZ myVgnVnZ2dnUVZ_ oTinZ2d@earthli nk.com...
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h /* mha: added */
    /* mha: removed silly macro */
    >
    int main(int argc, char *argv[])
    {
    if (argc != 4) {
    fputs("print usage error\n", stderr);
    exit(EXIT_FAILU RE);
    }
    if (isalpha(argv[1]) || isalpha(argv[2])) {
    fputs("name is 3rd arg\n", stderr);
    exit(EXIT_FAILU RE);
    }
    double x, y;
    FILE *fp;
    x = strtod(argv[1], NULL);
    y = strtod(argv[2], NULL);
    if (!(fp = fopen(argv[3], "a"))) { /* mha: fixed parenthesis
    error */
    fputs("fopen error\n", stderr);
    exit(EXIT_FAILU RE);
    }
    fprintf(fp, "%.2f %.2f\n", x, y); /* mha: fixed multiple errors
    in arguments to fprintf.
    Since there is no way to be
    sure what you are trying to
    do, I had to guess. */
    if (fclose(fp) == EOF) { /* mha: fixed parenthesis error and
    completely bogus comparison to
    NULL */
    fputs("fclose error\n", stderr);
    exit(EXIT_FAILU RE);
    }
    return 0;
    }
    Now I see that strchr is going to be needed here. I'm using headers too
    I've never used.

    Bill


    Comment

    • Bill Cunningham

      #17
      Re: sh?tpile of errors


      "Ian Collins" <ian-news@hotmail.co mwrote in message
      news:6fk536Fb53 97U12@mid.indiv idual.net...
      Why don't you learn to compile a few lines at a time?
      >
      How would I learn to do that? I've never received so many errors from a
      compiler before. I have surmised on my own strchr is going to be needed.
      Others say ctype.h which I've never used. Nothing like debugging with a few
      others more experienced ;)

      Bill


      Comment

      • Bill Cunningham

        #18
        Re: sh?tpile of errors


        "Bill Cunningham" <nospam@nspam.c omwrote in message
        news:qh6lk.102$ mP.55@trnddc03. ..
        >
        "Robert Gamble" <rgamble99@gmai l.comwrote in message
        news:90d06de5-8b5b-418c-b545-3d0d9aa47a75@k1 3g2000hse.googl egroups.com...
        >
        ... and you don't seem to be able to
        meaningfully incorporate the answers you have received in this group
        into your education.
        I am also writing small utilities now. Debugging with others helps you
        see your own errors also. I am seeing ways now that I can improve the code
        that I would never have been able to see without the involvement of others.

        clc is a good place for group debugging.

        Bill


        Comment

        • Richard Heathfield

          #19
          Re: sh?tpile of errors

          [Quoting marks fixed]

          Bill Cunningham said:
          >
          "Robert Gamble" <rgamble99@gmai l.comwrote in message
          news:90d06de5-8b5b-418c-b545-3d0d9aa47a75@k1 3g2000hse.googl egroups.com...
          >
          >... and you don't seem to be able to
          >meaningfully incorporate the answers you have received in this group
          >into your education.
          >
          I strongly disagree.
          Robert is right.
          I've never use ctype or even talked about for example.
          You missed his point. You still haven't understood the basics of a printf
          call, and yet you've rushed ahead onto ctype functions (which you don't
          understand either). This flies in the face of all the advice you've
          received - to master each new concept thoroughly before moving on to
          another. This is an important aspect of learning, and one that you seem
          determined to ignore, despite everyone's pleas.

          Until you stop flailing around at random, you will never learn C.

          Mark Pappin gave you a great chance to rationalise your learning process
          and gain a good teacher at the same time, but you threw that chance away.

          In fact, you throw away so many chances and come up with so many creative
          misunderstandin gs that I am convinced you are doing it deliberately. The
          way you are behaving cannot be explained by mere incompetence.

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

          • Keith Thompson

            #20
            Re: sh?tpile of errors

            "Bill Cunningham" <nospam@nspam.c omwrites:
            Would anyone be interested in giving this a quick look. The compiler
            gave me so many errors I don't know where to start. This is my first use of
            isalpha.
            >
            #include <stdio.h>
            #include <stdlib.h>
            #define ex exit(EXIT_FAILU RE)
            >
            int main(int argc, char *argv[])
            {
            if (argc != 4) {
            puts("print usage error");
            ex;
            }
            if (isalpha(argv[1]) || isalpha(argv[2])) {
            puts("name is 3rd arg");
            ex;
            }
            double x, y;
            FILE *fp;
            x = strtod(argv[1], NULL);
            y = strtod(argv[2], NULL);
            if (fp = fopen(argv[3], "a"))
            == NULL) {
            puts("fopen error");
            ex;
            }
            fprintf(argv[3], "%.2f", x, y);
            if (fclose(fp))
            == NULL) {
            puts("fclose error");
            ex;
            }
            return 0;
            }
            >
            I dunno sigh..
            Starting with the first error your compiler reports. Ignore all the
            other errors until you've fixed the first one. Recompile. Later,
            rinse, repeat.

            Style point: Drop the "ex" macro. When you want to write
            exit(EXIT_FAILU RE), just write exit(EXIT_FAILU RE); it's *much*
            clearer, since you don't force the reader to figure out what "ex"
            means. Don't use macros to save typing; that's not what they're for.

            And I'll discuss just one of several errors you've made. You write

            if (fclose(fp) == NULL) { ...

            (Well, almost; I've deleted an extra ')'.) What type does fclose()
            return? Why are you comparing its result to NULL?

            You know that fclose(fp) is the way to close a file; that's good. But
            you should have the documentation in front of you, and understand the
            types and meanings of any arguments and of the return type, before you
            even type the 'f'. The same applies to any standard function (for
            example, your incorrect fprintf call in the previous line).

            You obviously guessed that fclose() returns a pointer. You guessed
            wrong. That's not necessarily a bad thing, but rather than checking
            your guess, you went ahead and wrote the call and posted it here.

            And you can't depend on the compiler to catch all your errors for you.
            For reasons I won't go into right now, a compiler won't necessarily
            flag the error of comparing (fclose(fp) == NULL); you could silently
            get code that just does the wrong thing.

            Take the extra time to check the documentation. It will save you (and
            us!) time and effort in the long run.

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

            • Bill Cunningham

              #21
              Re: sh?tpile of errors


              "Richard Heathfield" <rjh@see.sig.in validwrote in message
              news:2rWdnTCk7J V1bgnVnZ2dnUVZ8 sednZ2d@bt.com. ..
              Mark Pappin gave you a great chance to rationalise your learning process
              and gain a good teacher at the same time, but you threw that chance away.
              Maybe he's right from a point of view. Richard I don't think the
              tutorial from Mark as well meant as it was was a good idea. Not for him or
              me. I'm suprised we made it to question 4. I sometimes need to be almost fed
              by the spoonful on this stuff. Maybe hard learning group debugging and k&r2
              is the way for me. Then I will eventually learn C. I really don't think Mark
              had the patience needed for one like me. What I need is an "LD" teacher.
              Anyway from now on I would only like to ask for debugging advice when
              necessary a little learning and for the most part we can go our ways.

              Bill


              Comment

              • Martien Verbruggen

                #22
                Re: sh?tpile of errors

                On Sat, 2 Aug 2008 11:21:05 -0700,
                osmium <r124c4u102@com cast.netwrote:
                "Bill Cunningham" wrote:
                >
                > Would anyone be interested in giving this a quick look. The compiler
                >gave me so many errors I don't know where to start. This is my first use
                >of isalpha.
                >
                It is not unusual to see a huge number of errors. Start with the first
                error and work downward, that's the way the compiler encountered them.
                That is good advice.

                In the below, I'm only going to correct your other advice, and won't try
                to play compiler for Bill. All diagnostics needed to 'fix' this program
                are provided by his compiler, assuming he allows it to.
                >int main(int argc, char *argv[])
                >{
                > if (argc != 4) {
                >puts("print usage error");
                >ex;
                > }
                > if (isalpha(argv[1]) || isalpha(argv[2])) {
                >
                *** extra ')' above
                Not above. Below.
                >puts("name is 3rd arg");
                >ex;
                > }
                > double x, y;
                > FILE *fp;
                > x = strtod(argv[1], NULL);
                > y = strtod(argv[2], NULL);
                > if (fp = fopen(argv[3], "a"))
                Here.
                >== NULL) {
                >puts("fopen error");
                >ex;
                >}
                > fprintf(argv[3], "%.2f", x, y);
                > if (fclose(fp))
                And here.

                Martien
                --
                |
                Martien Verbruggen | +++ Out of Cheese Error +++ Reinstall
                | Universe and Reboot +++
                |

                Comment

                • Bill Cunningham

                  #23
                  Re: sh?tpile of errors


                  "Keith Thompson" <kst-u@mib.orgwrote in message
                  news:lnr697c6mk .fsf@nuthaus.mi b.org...
                  Take the extra time to check the documentation. It will save you (and
                  us!) time and effort in the long run.
                  >
                  I confuse the return types quite a bit. I was going from memory. I need
                  to do just what you said basically on this one. ctype.h is a new one to me.

                  Bill


                  Comment

                  • Richard Heathfield

                    #24
                    Re: sh?tpile of errors

                    Bill Cunningham said:
                    >
                    "Richard Heathfield" <rjh@see.sig.in validwrote in message
                    news:2rWdnTCk7J V1bgnVnZ2dnUVZ8 sednZ2d@bt.com. ..
                    >Mark Pappin gave you a great chance to rationalise your learning process
                    >and gain a good teacher at the same time, but you threw that chance
                    >away.
                    >
                    Maybe he's right from a point of view. Richard I don't think the
                    tutorial from Mark as well meant as it was was a good idea.
                    I don't think he was offering you a tutorial. To use a swimming analogy, he
                    was offering you a lifeline, but it seems that you don't want to grasp it;
                    you'd rather thrash about, yelling "help" as loud as you can while at the
                    same time seeing how far out to sea you can get and how powerful a current
                    you can find.
                    Not for him or me.
                    Certainly not for him. Nobody has that much spare time.
                    I'm suprised we made it to question 4. I sometimes need to be
                    almost fed by the spoonful on this stuff.
                    Spoon-feeding is for babies, not for programmers. There is no mental
                    activity regularly undertaken by large numbers of people that is quite so
                    difficult as programming. Even lousy programmers have to be pretty bright,
                    and those who - maybe through no fault of their own - have major
                    difficulties with learning new things are going to find programming
                    impossible, because there is so much to learn *and retain*.
                    Maybe hard learning group debugging and k&r2 is the way for me.
                    I disagree. If you have to rely on others to do your debugging for you,
                    you're not actually learning *anything*. In any case, you haven't reached
                    the debugging stage yet. You're still at the "it won't compile" stage, and
                    you can't even balance parentheses. At your current rate of progress, I
                    shudder to think how long it will take before you can routinely write
                    moderate amounts of code without troubling the compiler's diagnostic
                    subsystem.
                    Then I will eventually learn C.
                    I doubt it. Life is not a story-book. Determination is necessary, but
                    insufficient on its own. You need other qualities to achieve your goals,
                    and if you want to learn C one of the other qualities you need is mental
                    discipline, which you appear to lack in bucketfuls.
                    I
                    really don't think Mark had the patience needed for one like me. What I
                    need is an "LD" teacher.
                    Then I suggest you find one. But you are unlikely to find one here.
                    Anyway from now on I would only like to ask for debugging advice when
                    necessary a little learning and for the most part we can go our ways.
                    If you ignore what you are told, why should anyone bother to tell you
                    anything?

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

                    • vippstar@gmail.com

                      #25
                      Re: sh?tpile of errors

                      On Aug 3, 2:44 am, "Bill Cunningham" <nos...@nspam.c omwrote:
                      "Jens Thoms Toerring" <j...@toerring. dewrote in messagenews:6fj umiFbrhl5U1@mid .uni-berlin.de...
                      >
                      A) There is no prototype for isalpha() in scope, you forgot to
                      include <ctype.h>
                      B) isalpha() expects an int (typically a char, cast to int) as
                      its argument, but you pass it a pointer to a string.
                      >
                      [snip]
                      >
                      Thanks Jen. I've never used of thought of ctype.h.
                      Speak english?

                      Comment

                      • Bill Cunningham

                        #26
                        Re: sh?tpile of errors


                        "Malcolm McLean" <regniztar@btin ternet.comwrote in message
                        news:4KGdnUNkFL 2-WAnVnZ2dnUVZ8s3 inZ2d@bt.com...
                        \However
                        1) you need to include ctype.h for the isalpha prototype
                        2) the function works on a single character, not a string, so you need to
                        pass
                        it argv[1][0], presuming that you want to check the first character of
                        argv[1].
                        You are introducing to me a new concept. One I've been waiting to see in
                        action and no one has ever said anything about it to me before. The reason
                        for a char**. So that's how it works. Each argument value of course has two
                        dimensional elements. If argv[1] is a string saying "hello world" then he is
                        at argv[1][0] and argv[1][1] right? This might sound simple but I haven't
                        been introduced to multi-dimensional arrays. But I know that's what you're
                        speaking of.

                        Bill


                        Comment

                        • Richard

                          #27
                          Re: sh?tpile of errors

                          Richard Heathfield <rjh@see.sig.in validwrites:
                          [Quoting marks fixed]
                          >
                          Bill Cunningham said:
                          >
                          >>
                          >"Robert Gamble" <rgamble99@gmai l.comwrote in message
                          >news:90d06de 5-8b5b-418c-b545-3d0d9aa47a75@k1 3g2000hse.googl egroups.com...
                          >>
                          >>... and you don't seem to be able to
                          >>meaningfull y incorporate the answers you have received in this group
                          >>into your education.
                          >>
                          >I strongly disagree.
                          >
                          Robert is right.
                          As was I months ago and was roundly condemned for being a troll. You can
                          not teach the kind of mindset which makes a programmer. Bill does not
                          have it. And he will never have it. For one of two reasons

                          1) He's just a troll having a good laugh at the regs trying to get some
                          browny points to balance against their other misdeeds.

                          or

                          2) He is simply unable to learn from experience.

                          I favour 1.

                          Comment

                          • Bill Cunningham

                            #28
                            Re: sh?tpile of errors


                            "Richard" <rgrdev@gmail.c omwrote in message
                            news:g7307u$mc3 $1@registered.m otzarella.org.. .

                            [snip]
                            1) He's just a troll having a good laugh at the regs trying to get some
                            browny points to balance against their other misdeeds.
                            >
                            I am unaware of anyone on clc's "misdeeds". I condemn no one here for
                            anything nor will I "get back" at anyone for doing anything to me because no
                            one here has.

                            Bill


                            Comment

                            • CBFalconer

                              #29
                              Re: sh?tpile of errors

                              Bill Cunningham wrote:
                              "Jens Thoms Toerring" <jt@toerring.de wrote in message
                              >
                              >A) There is no prototype for isalpha() in scope, you forgot to
                              > include <ctype.h>
                              >B) isalpha() expects an int (typically a char, cast to int) as
                              > its argument, but you pass it a pointer to a string.
                              >
                              [snip]
                              >
                              Thanks Jen. I've never used of thought of ctype.h.
                              If you want to use a function the first thing is to look up its
                              action and parameters in the C standard. At the same time you will
                              find a listing of the <include.hfil e to #include. Then you can
                              use the function with some clarity.

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


                              Comment

                              • D. Power

                                #30
                                Re: sh?tpile of errors

                                In article <W21lk.68$EL2.4 1@trnddc01>,
                                "Bill Cunningham" <nospam@nspam.c omwrote:
                                Would anyone be interested in giving this a quick look. The compiler
                                gave me so many errors I don't know where to start. This is my first use of
                                isalpha.
                                >
                                #include <stdio.h>
                                #include <stdlib.h>
                                #define ex exit(EXIT_FAILU RE)
                                >
                                int main(int argc, char *argv[])
                                {
                                if (argc != 4) {
                                puts("print usage error");
                                ex;
                                }
                                if (isalpha(argv[1]) || isalpha(argv[2])) {
                                puts("name is 3rd arg");
                                ex;
                                }
                                double x, y;
                                FILE *fp;
                                x = strtod(argv[1], NULL);
                                y = strtod(argv[2], NULL);
                                if (fp = fopen(argv[3], "a"))
                                == NULL) {
                                puts("fopen error");
                                ex;
                                }
                                fprintf(argv[3], "%.2f", x, y);
                                if (fclose(fp))
                                == NULL) {
                                puts("fclose error");
                                ex;
                                }
                                return 0;
                                }
                                >
                                I dunno sigh..
                                >
                                Bill

                                Try #include'ing the standard header where isalpha is defined; <ctype.h>

                                --
                                D. Power
                                "I hold it to be the inalienable right of anybody to go to hell in his
                                own way."
                                -Robert Frost

                                Comment

                                Working...