Pascal - C (2)

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

    #31
    Re: Pascal - C (2)

    On Sun, 2 Nov 2008 12:50:11 +0000 (UTC), Harald van D?k
    <truedfx@gmail. comwrote:
    >On Sun, 02 Nov 2008 01:28:00 -0700, Barry Schwarz wrote:
    >On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <jacob@nospam.c om>
    >wrote:
    >>>Ruud wrote:
    >>>2) In Pascal there exists the "in" function. Example:
    >>>>
    >>> if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }
    >>>>
    >>>This can be translated like:
    >>>>
    >>> if ( ((c >= 'A') && (c <= 'Z'))
    >>> || ((c >= '0') && (c <= '9'))) .... // c is hexadecimal
    >>>>
    >>>I just wonder if there is a more simpler solution.
    >>>
    >>>That one is simple enough
    >>
    >Except for the fact that it doesn't work on an EBCDIC system.
    >
    >It will (after fixing 'Z' so that it reads 'F') work on ASCII end EBCDIC
    >systems. In theory, there could be other systems where it will fail. I
    >doubt there are any such systems in practise, though.
    On EBCDIC systems, a-f are also valid hex digits. The same is true on
    Solaris systems. Even in standard C, the conversion specification "x"
    produces a-f while"X" produces A-F. Surely each of the characters
    produced either way is a valid hex character.

    --
    Remove del for email

    Comment

    • Keith Thompson

      #32
      Re: Pascal - C (2)

      jacob navia <jacob@nospam.c omwrites:
      Ruud wrote:
      >Hallo allemaal,
      >Many thanks for the massive response!
      >jacob navia wrote:
      >>If you do not know enough C please do not use this group.
      >
      >Then please be a good man and tell me what level I should have before
      >I can attend this group?
      >
      As you can see from my quotes, I do not told YOU that but to Ian
      Collins. Please try to understand how quoting works.
      I think he understood that. If your remark was intended only for Ian
      Collins, you could have sent him e-mail. You seemed to be mandating
      some minimum level of knowledge as a requirement for posting here;
      surely such a rule would not apply only to Ian Collins. Ruud just
      wanted to you clarify the rules.

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

        #33
        Re: Pascal - C (2)

        Barry Schwarz <schwarzb@dqel. comwrites:
        On Sun, 2 Nov 2008 12:50:11 +0000 (UTC), Harald van D?k
        <truedfx@gmail. comwrote:
        >
        >>On Sun, 02 Nov 2008 01:28:00 -0700, Barry Schwarz wrote:
        >>On Sat, 01 Nov 2008 23:26:37 +0100, jacob navia <jacob@nospam.c om>
        >>wrote:
        >>>>Ruud wrote:
        >>>>2) In Pascal there exists the "in" function. Example:
        >>>>>
        >>>> if (c in ['A'..'F', '0'..'9']) then { c is hexadecimal }
        >>>>>
        >>>>This can be translated like:
        >>>>>
        >>>> if ( ((c >= 'A') && (c <= 'Z'))
        >>>> || ((c >= '0') && (c <= '9'))) .... // c is hexadecimal
        >>>>>
        >>>>I just wonder if there is a more simpler solution.
        >>>>
        >>>>That one is simple enough
        >>>
        >>Except for the fact that it doesn't work on an EBCDIC system.
        >>
        >>It will (after fixing 'Z' so that it reads 'F') work on ASCII end EBCDIC
        >>systems. In theory, there could be other systems where it will fail. I
        >>doubt there are any such systems in practise, though.
        >
        On EBCDIC systems, a-f are also valid hex digits. The same is true on
        Solaris systems. Even in standard C, the conversion specification "x"
        produces a-f while"X" produces A-F. Surely each of the characters
        produced either way is a valid hex character.
        Maybe the OP has some specific reason to accept only uppercase
        letters. (Or maybe he just forgot about lowercase letters.)

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

        • dj3vande@csclub.uwaterloo.ca.invalid

          #34
          Re: Pascal - C (2)

          In article <gek9ce$uv0$1@r egistered.motza rella.org>,
          Eric Sosman <esosman@ieee-dot-org.invalidwrot e:

          [Copying a single character into a string]
          "Better" is a slippery word. There are certainly "other"
          >ways, such as
          >
          > strcpy(Str1, Str2);
          > Str1[ strlen(Str2) ] = Str3[5];
          > Str1[ strlen(Str2) ] = '\0';
          That last line looks wrong to me; I think you want to add 1 to
          strlen(Str2) before you use it as an index into Str1.

          If I were writing that code, I would probably use something like this
          instead:
          strcpy(Str1,Str 2);
          len=strlen(Str1 );
          Str1[len++]=Str3[5];
          Str1[len++]='\0';

          This is also a case where strncat's (generally confusing)
          interpretation of its count argument turns out to be useful:
          strcpy(Str1,Str 2);
          strncat(Str1,St r3+5,1);
          (But be careful using this one in code that has to be maintained.)


          dave

          --
          Dave Vandervies dj3vande at eskimo dot com
          You are determined to martyr yourself on a nonexistent altar
          An altar could be arranged.
          --Mark McIntyre and Richard Heathfield in comp.lang.c

          Comment

          • Eric Sosman

            #35
            Re: Pascal - C (2)

            dj3vande@csclub .uwaterloo.ca.i nvalid wrote:
            In article <gek9ce$uv0$1@r egistered.motza rella.org>,
            Eric Sosman <esosman@ieee-dot-org.invalidwrot e:
            >
            [Copying a single character into a string]
            >
            > "Better" is a slippery word. There are certainly "other"
            >ways, such as
            >>
            > strcpy(Str1, Str2);
            > Str1[ strlen(Str2) ] = Str3[5];
            > Str1[ strlen(Str2) ] = '\0';
            >
            That last line looks wrong to me; I think you want to add 1 to
            strlen(Str2) before you use it as an index into Str1.
            Right you are. Thanks.
            If I were writing that code, I would probably use something like this
            instead:
            strcpy(Str1,Str 2);
            len=strlen(Str1 );
            Str1[len++]=Str3[5];
            Str1[len++]='\0';
            >
            This is also a case where strncat's (generally confusing)
            interpretation of its count argument turns out to be useful:
            strcpy(Str1,Str 2);
            strncat(Str1,St r3+5,1);
            (But be careful using this one in code that has to be maintained.)
            ... and now you need to tack on the terminating '\0'
            that strncat() didn't give you. (We're both obviously
            suffering from the effects of a 25-hour day, and besides:
            Turnabout is fair play.)

            --
            Eric Sosman
            esosman@ieee-dot-org.invalid

            Comment

            • CBFalconer

              #36
              Re: Pascal - C (2)

              jacob navia wrote:
              Ruud wrote:
              >jacob navia wrote:
              >>
              >>If you do not know enough C please do not use this group.
              >>
              >Then please be a good man and tell me what level I should have
              >before I can attend this group?
              >
              As you can see from my quotes, I do not told YOU that but to
              Ian Collins. Please try to understand how quoting works.
              Jacob (and others), Usenet is NOT for private communications. Any
              such should be done via email, if possible. All Usenet messages
              are totally public, and addressed to the general readership. They
              are delivered to the readership, barring plonking etc.

              You have been told this before, but you persist in the same error.

              The following is primarily for Ruuds benefit, but all are invited
              to examine the referances. The C99 items (n869_txt.bz2 is bzip2
              compressed) describe the standard, and all functions in the
              standard library. The dinkumware reference is also an excellent
              introduction the the standard library.

              Some useful references about C:
              <http://www.ungerhu.com/jxh/clc.welcome.txt >
              <http://c-faq.com/ (C-faq)
              <http://benpfaff.org/writings/clc/off-topic.html>
              <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf(C99)
              <http://cbfalconer.home .att.net/download/n869_txt.bz2 (pre-C99)
              <http://www.dinkumware. com/c99.aspx (C-library}
              <http://gcc.gnu.org/onlinedocs/ (GNU docs)
              <http://clc-wiki.net/wiki/C_community:com p.lang.c:Introd uction>

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

              Comment

              • jacob navia

                #37
                Re: Pascal - C (2)

                CBFalconer wrote:
                jacob navia wrote:
                >Ruud wrote:
                >>jacob navia wrote:
                >>>
                >>>If you do not know enough C please do not use this group.
                >>Then please be a good man and tell me what level I should have
                >>before I can attend this group?
                >As you can see from my quotes, I do not told YOU that but to
                >Ian Collins. Please try to understand how quoting works.
                >
                Jacob (and others), Usenet is NOT for private communications.
                Hey you, can't you read? My answer was public.

                This is a typical facloner post.

                he doesn't knopw wnything of what's going on, and goes around
                by "keywords". He sees "jacobn" then, of course it must be wrong!


                Any
                such should be done via email, if possible. All Usenet messages
                are totally public, and addressed to the general readership. They
                are delivered to the readership, barring plonking etc.
                >
                You have been told this before, but you persist in the same error.
                >
                Yes falconer. You have been told this but you persist:
                Read the messages and the context before spewing nonsense.


                1) The OP asked a question
                2) Ian collins said it wasn't possible to do that in C and that C
                wasn't appropiate language for string processing.
                I answered that post with a refultal and an example of how the OP
                question could be answered. My answer was to Ian Collin's reply.

                Look at the attributions now and follow the posts. It is not that
                difficult.

                Then, the OP misunderstood my quoting and thought I answered to him

                Then you saw that wrong reply and without looking you take your
                "professor chuck" hat and start spewing nonsense.

                --
                jacob navia
                jacob at jacob point remcomp point fr
                logiciels/informatique

                Comment

                • dj3vande@csclub.uwaterloo.ca.invalid

                  #38
                  Re: Pascal - C (2)

                  In article <gekuc2$atn$1@r egistered.motza rella.org>,
                  Eric Sosman <esosman@ieee-dot-org.invalidwrot e:
                  >dj3vande@csclu b.uwaterloo.ca. invalid wrote:
                  >[Copying a single character into a string]
                  >This is also a case where strncat's (generally confusing)
                  >interpretati on of its count argument turns out to be useful:
                  > strcpy(Str1,Str 2);
                  > strncat(Str1,St r3+5,1);
                  >(But be careful using this one in code that has to be maintained.)
                  >
                  ... and now you need to tack on the terminating '\0'
                  >that strncat() didn't give you.
                  It's strncpy that doesn't give a terminating '\0'; strncat copies at
                  most count characters from the source string to the end of the dest
                  string and then adds a '\0'. (I *did* say that it was confusing. I
                  had to check the man page to see which strncat was. I just checked
                  N1124, and it agrees with the man page (7.21.3.2).)


                  dave

                  --
                  Dave Vandervies dj3vande at eskimo dot com
                  A lot of comp.lang.c people are traditionalists . For a very long time, the
                  *only* date of celebration recognised all over Usenet was 1st April. In
                  comp.lang.c that is still more or less the case. --Richard Heathfield in CLC

                  Comment

                  • Eric Sosman

                    #39
                    Re: Pascal - C (2)

                    dj3vande@csclub .uwaterloo.ca.i nvalid wrote:
                    In article <gekuc2$atn$1@r egistered.motza rella.org>,
                    Eric Sosman <esosman@ieee-dot-org.invalidwrot e:>
                    >>[Copying a single character into a string]
                    >
                    >>This is also a case where strncat's (generally confusing)
                    >>interpretatio n of its count argument turns out to be useful:
                    >> strcpy(Str1,Str 2);
                    >> strncat(Str1,St r3+5,1);
                    >>(But be careful using this one in code that has to be maintained.)
                    > ... and now you need to tack on the terminating '\0'
                    >that strncat() didn't give you.
                    >
                    It's strncpy that doesn't give a terminating '\0'; strncat copies at
                    most count characters from the source string to the end of the dest
                    string and then adds a '\0'. (I *did* say that it was confusing. I
                    had to check the man page to see which strncat was. I just checked
                    N1124, and it agrees with the man page (7.21.3.2).)
                    (Sigh.) Not my day, is it? I must have forgotten not
                    to take my stupid pills ...

                    Thanks again.

                    --
                    Eric Sosman
                    esosman@ieee-dot-org.invalid

                    Comment

                    • Keith Thompson

                      #40
                      Re: Pascal - C (2)

                      dj3vande@csclub .uwaterloo.ca.i nvalid writes:
                      [...]
                      It's strncpy that doesn't give a terminating '\0'; strncat copies at
                      most count characters from the source string to the end of the dest
                      string and then adds a '\0'. (I *did* say that it was confusing. I
                      had to check the man page to see which strncat was. I just checked
                      N1124, and it agrees with the man page (7.21.3.2).)
                      N1256 is more up to date.



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

                      • CBFalconer

                        #41
                        Re: Pascal - C (2)

                        dj3vande@csclub .uwaterloo.ca.i nvalid wrote:
                        Eric Sosman <esosman@ieee-dot-org.invalidwrot e:
                        >
                        .... snip ...
                        >
                        >... and now you need to tack on the terminating '\0'
                        >that strncat() didn't give you.
                        >
                        It's strncpy that doesn't give a terminating '\0'; strncat copies
                        at most count characters from the source string to the end of the
                        dest string and then adds a '\0'. (I *did* say that it was
                        confusing. I had to check the man page to see which strncat was.
                        I just checked N1124, and it agrees with the man page (7.21.3.2).)
                        I suggest ignoring strncpy and its nuisances, and using strlcpy and
                        strlcat. These names are reserved, but you can change them.
                        Source code in standard C, and full documentation, are all
                        available at:

                        <http://cbfalconer.home .att.net/download/strlcpy.zip>

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

                        Comment

                        • dj3vande@csclub.uwaterloo.ca.invalid

                          #42
                          Re: Pascal - C (2)

                          In article <490E2A52.C7978 6D8@yahoo.com>,
                          CBFalconer <cbfalconer@mai neline.netwrote :
                          >I suggest ignoring strncpy and its nuisances, and using strlcpy and
                          >strlcat.
                          The case I was commenting on was one of the (admittedly few) cases
                          where strncat makes it *easier* to do The Right Thing than strlcat
                          would.


                          dave

                          --
                          Dave Vandervies dj3vande at eskimo dot com
                          Actually, I'm toying with approaching a mug-printing outfit to see if they can
                          do me an Emacs reference quart-sized mug although I fear that the text might
                          still be too small to read. --Peter Corlett in the scary devil monastery

                          Comment

                          • Keith Thompson

                            #43
                            Re: Pascal - C (2)

                            Pilcrow <Pilcrow6@gmail .comwrites:
                            On Sun, 02 Nov 2008 10:59:20 +1300, Ian Collins <ian-news@hotmail.co m>
                            wrote:
                            >>Ruud wrote:
                            >>Sorry, no. One alternative is to use a regular expression library if
                            >>you have a lot of these.
                            >
                            Please. Point me to a regular expression library for C. Please.
                            A Google search for "C regular expression library" gets about 441,000
                            hits; many of the first few appear to be quite relevant.

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

                            • s0suk3@gmail.com

                              #44
                              Re: Pascal - C (2)

                              On Nov 2, 5:31 pm, CBFalconer <cbfalconer@yah oo.comwrote:
                              dj3vande@csclub .uwaterloo.ca.i nvalid wrote:
                              Eric Sosman  <esosman@ieee-dot-org.invalidwrot e:
                              >
                              ... snip ...
                              >
                              ... and now you need to tack on the terminating '\0'
                              that strncat() didn't give you.
                              >
                              It's strncpy that doesn't give a terminating '\0'; strncat copies
                              at most count characters from the source string to the end of the
                              dest string and then adds a '\0'.  (I *did* say that it was
                              confusing.  I had to check the man page to see which strncat was.
                              I just checked N1124, and it agrees with the man page (7.21.3.2).)
                              >
                              I suggest ignoring strncpy and its nuisances, and using strlcpy and
                              strlcat.  These names are reserved, but you can change them.
                              Source code in standard C, and full documentation, are all
                              available at:
                              >
                                <http://cbfalconer.home .att.net/download/strlcpy.zip>
                              So you bash powerful functions like asprintf(), but advocate trivial,
                              ten-liner functions like strlcpy() and strlcat()?

                              Sebastian

                              Comment

                              • Nick Keighley

                                #45
                                Re: Pascal - C (2)

                                On 2 Nov, 12:11, Ruud <Ruud.Baltis... @apg.nlwrote:
                                jacob navia wrote:
                                If you do not know enough C please do not use this group.
                                >
                                Then please be a good man and tell me what level I should have before
                                I can attend this group?
                                Jacob was talking rubbish

                                Chuck wrote:
                                <snip>
                                A good book, such as K&R II, would be helpful.
                                >
                                The book isn't the problem, see next.
                                >
                                Richard wrote:
                                Ruud, you use an odd quoting convention doesn't your
                                news software support the more usual conventions
                                (all the attributions at the top)?
                                Why not at least tell him about:
                                >
                                if(isupper(c) || isdigit(c))
                                >
                                and
                                >
                                if(strchr("ABCD EFGHIJKLMNOPQRS TUVWXYZ01234567 89", c) != NULL)
                                >
                                The problem is not knowing all those available functions.
                                yes, I remember all those functions and headers looked pretty
                                forbidding when I started learning C (also from pascal).
                                It didn't help that my implementation didn't distinguish
                                non-standard from standard headers.
                                And knowing
                                another language is a disavantage as well: instead of reading the book
                                line by line, one tends to look just at "how is this done in C".
                                K&R is pretty good for getting C idioms over. It really is
                                worth ploughing through K&R and doing the exercises. It's
                                not a big book (though information dense).

                                And even reading the book line by line isn't a guarantee for success:
                                there are no guarantees!
                                I justed searched the book "C in 21 days"
                                "xyz in small number days" isn't usually a promising title.
                                Really, give K&R a try.

                                I've got a book that promises to teach me to ride a horse in
                                a weekend...
                                for 'isdigit' and only found
                                one source file using this function. OTOH, this source file also
                                mentioned the function 'isspace' and this function does exactly what
                                one of my own made function does; detecting white space.
                                >
                                sprintf
                                >
                                Not mentioned at all "C in 21 days"
                                oh dear. sprintf() is *really* useful.
                                :( Because 'printf' was well
                                explained, I never used the help function of Borland C to give it a
                                better look. I wish I had because I just did: I learned nothing new
                                about 'printf' but the page also mentioned 'sprintf' and many more
                                other functions.
                                >
                                Trent wrote:
                                strncat(Str1, &Str3[5], 1);
                                >
                                Here I have no excuse, it is mentioned very clearly in the book.

                                --
                                Nick Keighley

                                "ALGOL 60 was a language so far ahead of its time that it
                                was not only an improvement on its predecessors but also
                                on nearly all its successors".
                                --C.A.R. Hoare

                                Comment

                                Working...