sh?tpile of errors

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

    #61
    Re: sh?tpile of errors

    santosh <santosh.k83@gm ail.comwrites:
    Richard wrote:
    >"Bill Cunningham" <nospam@nspam.c omwrites:
    >
    >>Here's a reposting of the source.
    >>>
    >>#include <stdio.h>
    >>#include <stdlib.h>
    >>#include <ctype.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("print non alpha allowed");
    >> ex;
    >> }
    >> FILE *fp;
    >> double x,y;
    >> x=strtod(argv[1],NULL);
    >> y=strtod(argv[2],NULL);
    >> if (fp=fopen(argv[3],"a"))==EOF) {
    >> puts("fopen error");
    >> }
    >> fprintf(fp,"%.2 f",x,y);
    >> if (fclose(fp))==E OF) {
    >> puts("fclose error");
    >> }
    >>return 0;
    >>}
    >>
    >I needed a good laugh so I complied the rubbish above. It took 10
    >seconds to get it to compile with only warnings.
    >
    <snip>
    >
    Why republish horribly broken code when you aren't going to attempt to
    correct it?
    >
    That it compiles is beside the point.
    >
    Don't be such a moron all your life Santosh. It compiling is the first
    step to get Bill to fix his own bugs. So no, compiling it is NOT beside
    the point.

    Comment

    • Bill Cunningham

      #62
      Re: sh?tpile of errors

      Santosh or anyone,

      isalpha takes as its parameter an int. If it is testing to see if something
      is a char it doesn't make sense to me to take an int. What am I not seeing?



      This is a pretty good reference page. char **argv is the parameter I am
      passing to main. isalpha is not going to take this. It wants an int. Am I
      going to have to use atoi in here somewhere just to test if something is a
      char or not?

      Bill


      Comment

      • Keith Thompson

        #63
        Re: sh?tpile of errors

        "Bill Cunningham" <nospam@nspam.c omwrites:
        "Richard" <rgrdev@gmail.c omwrote in message
        news:g77e50$52s $1@registered.m otzarella.org.. .
        >
        Non production code!
        >
        Yes that's right Richard. Non production meant to be used only by me or I
        would use exit(EXIT_FAILU RE) everytime it is to be used and not the #define
        ex macro.
        In code meant to be used only by you, you can do anything you like.

        If you want to post it here and expect to get help, I suggest that you
        drop the "ex" macro and write "exit(EXIT_FILA URE)", so that it's
        easier for us to read your code and offer advice.

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

        • Keith Thompson

          #64
          Re: sh?tpile of errors

          "Bill Cunningham" <nospam@nspam.c omwrites:
          "Keith Thompson" <kst-u@mib.orgwrote in message
          news:lnwsixbz3w .fsf@nuthaus.mi b.org...
          >
          >Yes. (*blush*)
          >>
          You left me kinda scratching my head there on that one Keith. I'd never
          seen int *argv[] before. But what do I know.
          "int *argv[]" was a mistake on my part. Please ignore it.

          What I meant was "char *argv[]".

          To restore some context and correct my own error:

          argv can be declared either as char **argv or as char *argv[].

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

          • santosh

            #65
            Re: sh?tpile of errors

            Bill Cunningham wrote:
            >
            "santosh" <santosh.k83@gm ail.comwrote in message
            news:g77fjv$97o $1@registered.m otzarella.org.. .
            >
            >Why republish horribly broken code when you aren't going to attempt
            >to correct it?
            >>
            >That it compiles is beside the point.
            >
            This has been re-written Santosh. [ ... ]
            My question was at Richard.

            Comment

            • santosh

              #66
              Re: sh?tpile of errors

              Bill Cunningham wrote:
              Santosh or anyone,
              >
              isalpha takes as its parameter an int. If it is testing to see if
              something is a char it doesn't make sense to me to take an int. What
              am I not seeing?
              This question has been debated to death here. Just search the archives.

              >
              This is a pretty good reference page. char **argv is the parameter I
              am passing to main. isalpha is not going to take this.
              Right.
              It wants an
              int. Am I going to have to use atoi in here somewhere just to test if
              something is a char or not?
              No. What is the type of argv[n][n]? Will that be compatible with the
              type that isalpha takes?

              Comment

              • Keith Thompson

                #67
                Re: sh?tpile of errors

                "Bill Cunningham" <nospam@nspam.c omwrites:
                "William Pursell" <bill.pursell@g mail.comwrote in message
                news:d32ed3d0-4e12-4b31-8cbf-c5b3608030ff@79 g2000hsk.google groups.com...
                >
                Assuming gcc & bash, try:
                $ gcc foo.c 2>&1 | less
                Bill, if you can't get OE Quotefix to work for you, then please pay
                attention when you post a followup. If the article to which you're
                replying was posted through Google Groups, please do *something* to
                indicate the division between the quoted material and your new text.
                Here's a reposting of the source.
                >
                #include <stdio.h>
                #include <stdlib.h>
                #include <ctype.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("print non alpha allowed");
                ex;
                }
                FILE *fp;
                double x,y;
                x=strtod(argv[1],NULL);
                y=strtod(argv[2],NULL);
                if (fp=fopen(argv[3],"a"))==EOF) {
                puts("fopen error");
                }
                fprintf(fp,"%.2 f",x,y);
                if (fclose(fp))==E OF) {
                puts("fclose error");
                }
                return 0;
                }
                This still has syntax errors. Look at the line with the isalpha
                calls. Count the parentheses.

                Here's your next assignment. Do not post code that produces an error
                message containing the phrase "syntax error" or "parse error". In
                most cases, that will be the very first error reported by the
                compiler. Fix that error and recompile. Repeat until you have no
                syntax errors. *Then* you can post your code and ask for further
                help.

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

                  #68
                  Re: sh?tpile of errors


                  "santosh" <santosh.k83@gm ail.comwrote in message
                  news:g77hvk$fpe $1@registered.m otzarella.org.. .
                  > This has been re-written Santosh. [ ... ]
                  >
                  My question was at Richard.
                  My mistake.

                  Bill


                  Comment

                  • Richard

                    #69
                    Re: sh?tpile of errors

                    santosh <santosh.k83@gm ail.comwrites:
                    Bill Cunningham wrote:
                    >
                    > Santosh or anyone,
                    >>
                    >isalpha takes as its parameter an int. If it is testing to see if
                    >something is a char it doesn't make sense to me to take an int. What
                    >am I not seeing?
                    >
                    This question has been debated to death here. Just search the
                    archives.
                    So has every other question asked here. If you are not willing to
                    explain, why are you here? Will you refer posters to other posts about
                    casting the return of malloc, the return type of main etc? I doubt it.
                    >
                    >http://www.cppreference.com/stdstring/isalpha.html
                    >>
                    >This is a pretty good reference page. char **argv is the parameter I
                    >am passing to main. isalpha is not going to take this.
                    >
                    Right.
                    >
                    >It wants an
                    >int. Am I going to have to use atoi in here somewhere just to test if
                    >something is a char or not?
                    >
                    No. What is the type of argv[n][n]? Will that be compatible with the
                    type that isalpha takes?
                    >
                    You are wrong. He might well have to use it if the characters are there
                    as part of a command line integer parameter. He needs to convert the
                    character sequence to that integer.

                    --

                    Comment

                    • Bill Cunningham

                      #70
                      Re: sh?tpile of errors


                      "santosh" <santosh.k83@gm ail.comwrote in message
                      news:g77i4s$ahg $1@registered.m otzarella.org.. .
                      No. What is the type of argv[n][n]? Will that be compatible with the
                      type that isalpha takes?
                      Oh I see. I've never used argv[][]'s before. I see so much clearly now.
                      Thank you Thank you. I am going to try this code again.

                      Bill


                      Comment

                      • santosh

                        #71
                        Re: sh?tpile of errors

                        Richard wrote:
                        santosh <santosh.k83@gm ail.comwrites:
                        <snip>
                        >Why republish horribly broken code when you aren't going to attempt
                        >to correct it?
                        >>
                        >That it compiles is beside the point.
                        >>
                        >
                        Don't be such a moron all your life Santosh. It compiling is the first
                        step to get Bill to fix his own bugs.
                        No. Understanding C is the first step.

                        A typical C compiler will gladly accept highly bastardised C and will
                        attempt to generate an executable. Fixing errors reported by a compiler
                        *after* having learnt the language is one thing, but depending on
                        compiler diagnostics to learn the rules and semantics of C is not very
                        bright, IMO.
                        So no, compiling it is NOT beside the point.
                        Unless invoked in conforming mode an implementation is allowed to
                        silently accept anything and produce an executable. Even under
                        conforming mode, only diagnostics are guaranteed. Undefined behaviour
                        that is not a constraint violation might still be silently accepted and
                        typically you do *not* want that.

                        It's better to learn the language first and then use the compiler,
                        rather than depending on it to learn the language.

                        Bill should re-open K&R and start with the first page. I understand that
                        he has not progressed beyond the first few pages after several years,
                        but he really has no other alternative. Merely messing around with
                        programs written with guesswork and compiled with luck isn't going to
                        get him anywhere.

                        Comment

                        • santosh

                          #72
                          Re: sh?tpile of errors

                          Richard wrote:
                          santosh <santosh.k83@gm ail.comwrites:
                          >Bill Cunningham wrote:
                          >>char **argv is the parameter I am passing to main. isalpha is not
                          >>going to take this. It wants an int. Am I going to have to use atoi
                          >>in here somewhere just to test if something is a char or not?
                          >>
                          >No. What is the type of argv[n][n]? Will that be compatible with the
                          >type that isalpha takes?
                          >
                          You are wrong. He might well have to use it if the characters are
                          there as part of a command line integer parameter. He needs to convert
                          the character sequence to that integer.
                          Don't you find it tiresome to disagree just for the sake of it?

                          My response was directed at the specific complaint by Bill that
                          *isalpha* won't like argv as an argument. Clearly he wants to run
                          through the strings to check whether any of them contain alphabetic
                          characters (which would be error).

                          So what you say above makes no sense at all.

                          Comment

                          • Richard

                            #73
                            Re: sh?tpile of errors

                            santosh <santosh.k83@gm ail.comwrites:
                            Richard wrote:
                            >santosh <santosh.k83@gm ail.comwrites:
                            >
                            <snip>
                            >
                            >>Why republish horribly broken code when you aren't going to attempt
                            >>to correct it?
                            >>>
                            >>That it compiles is beside the point.
                            >>>
                            >>
                            >Don't be such a moron all your life Santosh. It compiling is the first
                            >step to get Bill to fix his own bugs.
                            >
                            No. Understanding C is the first step.
                            Sigh. Obviously.
                            >
                            A typical C compiler will gladly accept highly bastardised C and will
                            attempt to generate an executable. Fixing errors reported by a compiler
                            *after* having learnt the language is one thing, but depending on
                            compiler diagnostics to learn the rules and semantics of C is not very
                            bright, IMO.
                            Learning by doing Santosh. its why I recommend using a debugger. Clearly
                            Bill is incapable of reading code.

                            The point, which even you in your most "clc reg" mode must see that
                            fixing the bugs so he can COMPILE the code can only be benefifical. He
                            could not even match brackets for goodness sake.

                            Comment

                            • Richard

                              #74
                              Re: sh?tpile of errors

                              santosh <santosh.k83@gm ail.comwrites:
                              Richard wrote:
                              >santosh <santosh.k83@gm ail.comwrites:
                              >>Bill Cunningham wrote:
                              >
                              >>>char **argv is the parameter I am passing to main. isalpha is not
                              >>>going to take this. It wants an int. Am I going to have to use atoi
                              >>>in here somewhere just to test if something is a char or not?
                              >>>
                              >>No. What is the type of argv[n][n]? Will that be compatible with the
                              >>type that isalpha takes?
                              >>
                              >You are wrong. He might well have to use it if the characters are
                              >there as part of a command line integer parameter. He needs to convert
                              >the character sequence to that integer.
                              >
                              Don't you find it tiresome to disagree just for the sake of it?
                              I would if that were the reason. But you were wrong. Or appeared to be
                              wrong.

                              He asked if he could use atoi in there somewhere. And yes, he can
                              indeed. Remember we are talking about Bill. You talked about
                              isalpha. However he still needs the integer values from the chars passed
                              in.

                              Comment

                              • santosh

                                #75
                                Re: sh?tpile of errors

                                Richard wrote:
                                santosh <santosh.k83@gm ail.comwrites:
                                >
                                >Richard wrote:
                                >>santosh <santosh.k83@gm ail.comwrites:
                                >>
                                ><snip>
                                >>
                                >>>Why republish horribly broken code when you aren't going to attempt
                                >>>to correct it?
                                >>>>
                                >>>That it compiles is beside the point.
                                >>>>
                                >>>
                                >>Don't be such a moron all your life Santosh. It compiling is the
                                >>first step to get Bill to fix his own bugs.
                                >>
                                >No. Understanding C is the first step.
                                >
                                Sigh. Obviously.
                                >
                                >>
                                >A typical C compiler will gladly accept highly bastardised C and will
                                >attempt to generate an executable. Fixing errors reported by a
                                >compiler *after* having learnt the language is one thing, but
                                >depending on compiler diagnostics to learn the rules and semantics of
                                >C is not very bright, IMO.
                                >
                                Learning by doing Santosh. its why I recommend using a debugger.
                                Clearly Bill is incapable of reading code.
                                >
                                The point, which even you in your most "clc reg" mode must see that
                                fixing the bugs so he can COMPILE the code can only be benefifical. He
                                could not even match brackets for goodness sake.
                                The very reason he started this thread was because he *could* *not*
                                understand the errors and warnings his compiler gave him. And that is a
                                direct result of the fact that he has only correctly learnt a minuscule
                                fraction of C (though he incorrectly uses a rather larger portion of
                                it.)

                                You need to know the language to understand all but the most simple of
                                typical compiler messages. Us telling him how to fix the code to shut
                                the compiler up is no good, since he doesn't understand *why* those
                                fixes are needed. There really is no alternative for him but to keep
                                trying from the very beginning of a good tutorial, if he really is
                                serious about this.

                                I'm surprised that you advocate this "learning by doing" philosophy for
                                Bill of all the people. Someone who can't match parenthesis isn't going
                                to get very far with gdb or gcc. It's better to understand than to
                                learn.

                                Comment

                                Working...