Re: What am I doing wrong?

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

    Re: What am I doing wrong?

    On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@com cast.netsaid:
    Do you agree that ..
    >
    member,first,mi ,last,dob,eff_d ate,exp_date
    1,John,,Doe,07/04/1776,01/01/1800,
    2,Mack,T,Knife, 11/11/1918,10/1/1939,5/25/2005
    >
    .. might be the contents of your CSV file?
    Err, no not really as that has nothing to do with stock market prices :).
    --
    "I disapprove of what you say, but I'll defend to the death your right
    to say it." - Voltaire

  • Joe Wright

    #2
    Re: What am I doing wrong?

    Cromulent wrote:
    On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@com cast.netsaid:
    >Do you agree that ..
    >>
    >member,first,m i,last,dob,eff_ date,exp_date
    >1,John,,Doe, 07/04/1776,01/01/1800,
    >2,Mack,T,Knife ,11/11/1918,10/1/1939,5/25/2005
    >>
    >.. might be the contents of your CSV file?
    >
    Err, no not really as that has nothing to do with stock market prices :).
    Of course. I was talking about the format of the file. In the case of
    Microsoft Excel, Visual FoxPro and perhaps Access, CSV files are text
    representations of tables. The first row (line) of the CSV file are the
    names of the columns and subsequent lines are the values of the columns.

    Is this the kind of CSV file you are talking about or do you have some
    other idea?


    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---

    Comment

    • Cromulent

      #3
      Re: What am I doing wrong?

      On 2008-07-06 22:11:48 +0100, Joe Wright <joewwright@com cast.netsaid:
      Cromulent wrote:
      >On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@com cast.netsaid:
      >>Do you agree that ..
      >>>
      >>member,first, mi,last,dob,eff _date,exp_date
      >>1,John,,Doe,0 7/04/1776,01/01/1800,
      >>2,Mack,T,Knif e,11/11/1918,10/1/1939,5/25/2005
      >>>
      >>.. might be the contents of your CSV file?
      >>
      >Err, no not really as that has nothing to do with stock market prices :).
      >
      Of course. I was talking about the format of the file. In the case of
      Microsoft Excel, Visual FoxPro and perhaps Access, CSV files are text
      representations of tables. The first row (line) of the CSV file are the
      names of the columns and subsequent lines are the values of the columns.
      >
      Is this the kind of CSV file you are talking about or do you have some
      other idea?
      Ah, I see. Yes that is exactly the type of data I will be using. Here
      is an example:

      Date,Open,High, Low,Close,Volum e
      3-Jul-08,0.80,1.09,0. 80,1.09,77800
      2-Jul-08,1.08,1.09,0. 56,0.94,19600
      1-Jul-08,1.09,1.09,0. 95,1.08,29700
      30-Jun-08,0.80,1.09,0. 75,1.09,11500
      --
      "I disapprove of what you say, but I'll defend to the death your right
      to say it." - Voltaire

      Comment

      • Joe Wright

        #4
        Re: What am I doing wrong?

        Cromulent wrote:
        On 2008-07-06 22:11:48 +0100, Joe Wright <joewwright@com cast.netsaid:
        >
        >Cromulent wrote:
        >>On 2008-07-06 21:09:55 +0100, Joe Wright <joewwright@com cast.netsaid:
        >>>Do you agree that ..
        >>>>
        >>>member,first ,mi,last,dob,ef f_date,exp_date
        >>>1,John,,Doe, 07/04/1776,01/01/1800,
        >>>2,Mack,T,Kni fe,11/11/1918,10/1/1939,5/25/2005
        >>>>
        >>>.. might be the contents of your CSV file?
        >>>
        >>Err, no not really as that has nothing to do with stock market prices
        >>:).
        >>
        >Of course. I was talking about the format of the file. In the case of
        >Microsoft Excel, Visual FoxPro and perhaps Access, CSV files are text
        >representation s of tables. The first row (line) of the CSV file are
        >the names of the columns and subsequent lines are the values of the
        >columns.
        >>
        >Is this the kind of CSV file you are talking about or do you have some
        >other idea?
        >
        Ah, I see. Yes that is exactly the type of data I will be using. Here is
        an example:
        >
        Date,Open,High, Low,Close,Volum e
        3-Jul-08,0.80,1.09,0. 80,1.09,77800
        2-Jul-08,1.08,1.09,0. 56,0.94,19600
        1-Jul-08,1.09,1.09,0. 95,1.08,29700
        30-Jun-08,0.80,1.09,0. 75,1.09,11500
        Ok, thanks. I deal with these .csv files every day at my job. I haven't
        used strtok() in twenty years, since I figured out how it works.

        Given your example file, what do you want to do with the data?

        --
        Joe Wright
        "Everything should be made as simple as possible, but not simpler."
        --- Albert Einstein ---

        Comment

        • Cromulent

          #5
          Re: What am I doing wrong?

          On 2008-07-07 00:06:09 +0100, Joe Wright <joewwright@com cast.netsaid:
          >
          >>
          >Ah, I see. Yes that is exactly the type of data I will be using. Here
          >is an example:
          >>
          >Date,Open,High ,Low,Close,Volu me
          >3-Jul-08,0.80,1.09,0. 80,1.09,77800
          >2-Jul-08,1.08,1.09,0. 56,0.94,19600
          >1-Jul-08,1.09,1.09,0. 95,1.08,29700
          >30-Jun-08,0.80,1.09,0. 75,1.09,11500
          >
          Ok, thanks. I deal with these .csv files every day at my job. I haven't
          used strtok() in twenty years, since I figured out how it works.
          >
          Given your example file, what do you want to do with the data?
          Basically I want to split the component parts up. I want to keep the
          date and convert it to a useable form and then take each of the other
          components (open, high, low etc) and put them in the appropriate
          variable type. Then once I have all of them I want to be able to do
          certain mathmatically functions. To give a very simple example I want
          to be able to work out the moving average with the given data.
          --
          "I disapprove of what you say, but I'll defend to the death your right
          to say it." - Voltaire

          Comment

          • CBFalconer

            #6
            Re: What am I doing wrong?

            Cromulent wrote:
            Joe Wright <joewwright@com cast.netsaid:
            >
            >>Ah, I see. Yes that is exactly the type of data I will be using.
            >>Here is an example:
            >>>
            >>Date,Open,Hig h,Low,Close,Vol ume
            >>3-Jul-08,0.80,1.09,0. 80,1.09,77800
            >>2-Jul-08,1.08,1.09,0. 56,0.94,19600
            >>1-Jul-08,1.09,1.09,0. 95,1.08,29700
            >>30-Jun-08,0.80,1.09,0. 75,1.09,11500
            >>
            >Ok, thanks. I deal with these .csv files every day at my job. I
            >haven't used strtok() in twenty years, since I figured out how
            >it works.
            >>
            >Given your example file, what do you want to do with the data?
            >
            Basically I want to split the component parts up. I want to keep
            the date and convert it to a useable form and then take each of
            the other components (open, high, low etc) and put them in the
            appropriate variable type. Then once I have all of them I want to
            be able to do certain mathmatically functions. To give a very
            simple example I want to be able to work out the moving average
            with the given data.
            Please do not strip attribution lines for material you quote.
            Those are the initial lines of the form "Joe wrote:", and give
            credit to the authors.

            Try this:

            /* ------- file tknsplit.c ----------*/
            #include "tknsplit.h "

            /* copy over the next tkn from an input string, after
            skipping leading blanks (or other whitespace?). The
            tkn is terminated by the first appearance of tknchar,
            or by the end of the source string.

            The caller must supply sufficient space in tkn to
            receive any tkn, Otherwise tkns will be truncated.

            Returns: a pointer past the terminating tknchar.

            This will happily return an infinity of empty tkns if
            called with src pointing to the end of a string. Tokens
            will never include a copy of tknchar.

            A better name would be "strtkn", except that is reserved
            for the system namespace. Change to that at your risk.

            released to Public Domain, by C.B. Falconer.
            Published 2006-02-20. Attribution appreciated.
            Revised 2006-06-13 2007-05-26 (name)
            */

            const char *tknsplit(const char *src, /* Source of tkns */
            char tknchar, /* tkn delimiting char */
            char *tkn, /* receiver of parsed tkn */
            size_t lgh) /* length tkn can receive */
            /* not including final '\0' */
            {
            if (src) {
            while (' ' == *src) src++;

            while (*src && (tknchar != *src)) {
            if (lgh) {
            *tkn++ = *src;
            --lgh;
            }
            src++;
            }
            if (*src && (tknchar == *src)) src++;
            }
            *tkn = '\0';
            return src;
            } /* tknsplit */

            #ifdef TESTING
            #include <stdio.h>

            #define ABRsize 6 /* length of acceptable tkn abbreviations */

            /* ---------------- */

            static void showtkn(int i, char *tok)
            {
            putchar(i + '1'); putchar(':');
            puts(tok);
            } /* showtkn */

            /* ---------------- */

            int main(void)
            {
            char teststring[] = "This is a test, ,, abbrev, more";

            const char *t, *s = teststring;
            int i;
            char tkn[ABRsize + 1];

            puts(teststring );
            t = s;
            for (i = 0; i < 4; i++) {
            t = tknsplit(t, ',', tkn, ABRsize);
            showtkn(i, tkn);
            }

            puts("\nHow to detect 'no more tkns' while truncating");
            t = s; i = 0;
            while (*t) {
            t = tknsplit(t, ',', tkn, 3);
            showtkn(i, tkn);
            i++;
            }

            puts("\nUsing blanks as tkn delimiters");
            t = s; i = 0;
            while (*t) {
            t = tknsplit(t, ' ', tkn, ABRsize);
            showtkn(i, tkn);
            i++;
            }
            return 0;
            } /* main */

            #endif
            /* ------- end file tknsplit.c ----------*/

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

            Comment

            • Ben Bacarisse

              #7
              Re: What am I doing wrong?

              Cromulent <cromulent@just extrememetal.co mwrites:
              On 2008-07-07 00:06:09 +0100, Joe Wright <joewwright@com cast.netsaid:
              >>
              >>>
              >>Ah, I see. Yes that is exactly the type of data I will be
              >>using. Here is an example:
              >>>
              >>Date,Open,Hig h,Low,Close,Vol ume
              >>3-Jul-08,0.80,1.09,0. 80,1.09,77800
              >>2-Jul-08,1.08,1.09,0. 56,0.94,19600
              >>1-Jul-08,1.09,1.09,0. 95,1.08,29700
              >>30-Jun-08,0.80,1.09,0. 75,1.09,11500
              >>
              >Ok, thanks. I deal with these .csv files every day at my job. I
              >haven't used strtok() in twenty years, since I figured out how it
              >works.
              >>
              >Given your example file, what do you want to do with the data?
              >
              Basically I want to split the component parts up.
              You could do a lot worse than simply using fscanf. If you make the
              format quite strict and test the return you will be alerted to most
              input errors:

              char month[4], nl;
              double open, hi, lo, close;
              unsigned day, year, vol;
              ...
              if (fscanf("%2u-%3s-%2u,%lf,%lf,%lf ,%lf,%u%c",
              &day, month, &year, &open, &hi, &lo, &close, &vol, &nl) == 9
              && nl == '\n')

              --
              Ben.

              Comment

              • Richard Heathfield

                #8
                Re: What am I doing wrong?

                Bill Reid said:
                >
                Bill Reid <hormelfree@hap pyhealthy.netwr ote in message
                news:97xck.1028 49$102.35757@bg tnsc05-news.ops.worldn et.att.net...
                >
                DAMN!!! I hate it when that happens!!!
                It would happen less if you listened more.

                There are plenty of bright people in here.

                You can always tell the bright ones, because they are the ones who learn
                from other people's crits.

                And then there are those who, like Bill, take criticism as insult and
                respond to it with invective.

                Not so bright.

                Okay, Bill, flame away. Shouting is what you're good at, so you get on with
                your shouting and let the poor newbie get on with learning C from people
                who know it.

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

                • jacob navia

                  #9
                  Re: What am I doing wrong?

                  Richard Heathfield wrote:
                  Bill Reid said:
                  >
                  >Bill Reid <hormelfree@hap pyhealthy.netwr ote in message
                  >news:97xck.102 849$102.35757@b gtnsc05-news.ops.worldn et.att.net...
                  >>
                  >DAMN!!! I hate it when that happens!!!
                  >
                  It would happen less if you listened more.
                  >
                  There are plenty of bright people in here.
                  >
                  You can always tell the bright ones, because they are the ones who learn
                  from other people's crits.
                  >
                  And then there are those who, like Bill, take criticism as insult and
                  respond to it with invective.
                  >
                  Not so bright.
                  >
                  Okay, Bill, flame away. Shouting is what you're good at, so you get on with
                  your shouting and let the poor newbie get on with learning C from people
                  who know it.
                  >
                  Yes, for instance mr heathfield that can't figure out that pointers
                  aren't always 32 bits...

                  See "C unleashed"

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

                  Comment

                  • Ron Ford

                    #10
                    Re: What am I doing wrong?

                    On Tue, 08 Jul 2008 09:36:46 +0200, jacob navia posted:
                    Richard Heathfield wrote:
                    >Bill Reid said:
                    >>
                    >>Bill Reid <hormelfree@hap pyhealthy.netwr ote in message
                    >>news:97xck.10 2849$102.35757@ bgtnsc05-news.ops.worldn et.att.net...
                    >>>
                    >>DAMN!!! I hate it when that happens!!!
                    >>
                    >It would happen less if you listened more.
                    >>
                    >There are plenty of bright people in here.
                    >>
                    >You can always tell the bright ones, because they are the ones who learn
                    >from other people's crits.
                    >>
                    >And then there are those who, like Bill, take criticism as insult and
                    >respond to it with invective.
                    >>
                    >Not so bright.
                    >>
                    >Okay, Bill, flame away. Shouting is what you're good at, so you get on with
                    >your shouting and let the poor newbie get on with learning C from people
                    >who know it.
                    >>
                    >
                    Yes, for instance mr heathfield that can't figure out that pointers
                    aren't always 32 bits...
                    >
                    See "C unleashed"
                    I couldn't find the guarantee of 32-bit pointers. I don't think it's any
                    big secret that there were a lot of errors. My favorite of the whoppers is
                    Jack Klein's visualization of an error-correcting Hamming code announced as
                    (12,4) instead of (12,8), which completely reverses the role of the parity
                    and data bits.
                    --
                    I hate all sports as rabidly as a person who likes sports hates common
                    sense.
                    H. L. Mencken

                    Comment

                    • Richard Heathfield

                      #11
                      Re: What am I doing wrong?

                      Ron Ford said:
                      On Tue, 08 Jul 2008 09:36:46 +0200, jacob navia posted:
                      <snip>
                      >>
                      >Yes, for instance mr heathfield that can't figure out that pointers
                      >aren't always 32 bits...
                      (Mr Heathfield's first encounter with C pointers was in MS-DOS, in which
                      pointers are 20 bits, and there are various 16- and 32-bit bodges
                      available to deal with this weirdity - and Mr Heathfield has also worked
                      on systems with other pointer sizes, so Mr Heathfield is well aware that
                      pointer size is not written in stone. Perhaps Mr Navia would be so kind as
                      to point out where CU claims that pointers are always 32 bits?)
                      >>
                      >See "C unleashed"
                      Which bit?
                      I couldn't find the guarantee of 32-bit pointers. I don't think it's any
                      big secret that there were a lot of errors.
                      No, it's no secret. We've documented as many as we can find. It would be
                      nice to have the chance to go back and have another crack at it, fix all
                      this stuff, but unfortunately that isn't going to happen, but we've done
                      what we can.

                      This is an illustration of my earlier point - that the bright response to
                      bug reports is to investigate the reports and, in cases where the reports
                      are correct, to put them right if possible, or at least to record them,
                      publish them, and learn from them. NOT to yell at the guy who made the
                      crit. There are several people in comp.lang.c who have yet to learn this.

                      <snip>

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

                      • jacob navia

                        #12
                        Re: What am I doing wrong?

                        Richard Heathfield wrote:

                        Perhaps Mr Navia would be so kind as
                        to point out where CU claims that pointers are always 32 bits?)
                        Specifically in Chapter 11, page 353 you assume
                        sizeof pointer is equal to sizeof int...

                        It will work when sizeof pointer is equal to sizeof int
                        (windows or linux 32 bit versions) but will crash when
                        sizeof int != sizeof pointer (windows 64 bits.

                        I would never mind that you have a bug. What bothers me
                        is how you make fun of other people when they try to
                        write something and have a bug!

                        This slightly ironic tone, this "dettached" viewpoint,
                        as you never make those kind of errors.


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

                        Comment

                        • Richard Heathfield

                          #13
                          Re: What am I doing wrong?

                          jacob navia said:
                          Richard Heathfield wrote:
                          >
                          Perhaps Mr Navia would be so kind as
                          >to point out where CU claims that pointers are always 32 bits?)
                          >
                          Specifically in Chapter 11, page 353 you assume
                          sizeof pointer is equal to sizeof int...
                          I don't see it. I *do* see where I assume that sizeof(int **) is equivalent
                          to sizeof(int *), which is itself a bug - one that was first reported (by
                          Chris Mears) and published (almost) EIGHT YEARS AGO - but a far cry from
                          assuming that pointers are always 32 bits. I can't see the number 32
                          anywhere on that page.

                          I think the simplest explanation of your claim is that you have made two
                          errors here: 1) you have assumed that ints are always 32 bits; 2) you have
                          misread my code as if it assumed that sizeof pointer is equal to sizeof
                          int. Given those errors, it is easy to see why you might think I'd claimed
                          pointers are 32 bits. But those are your mistakes, not mine.

                          You made an incorrect claim, or at least a claim that you have not
                          substantiated - that CU claims pointers are always 32 bits. Your attempted
                          substantiation, Ch 11 p353, modified the claim itself, and the modified
                          claim was also incorrect. And the bug that /is/ there was documented on
                          the errata page in November 2000.

                          It will work when sizeof pointer is equal to sizeof int
                          (windows or linux 32 bit versions) but will crash when
                          sizeof int != sizeof pointer (windows 64 bits.
                          >
                          I would never mind that you have a bug. What bothers me
                          is how you make fun of other people when they try to
                          write something and have a bug!
                          I don't make fun of people for making mistakes. I do sometimes make fun of
                          people for refusing to learn from them.
                          This slightly ironic tone, this "dettached" viewpoint,
                          I save the ironic tone for special occasions, which are fewer than they
                          used to be, now that the Terrible Triplets are safely behind plonkbars.
                          The detached viewpoint is one that you would do well to cultivate. It
                          might well bring your blood pressure down.
                          as you never make those kind of errors.
                          Everybody makes mistakes. The question is not whether we are perfect, but
                          whether we are striving to become perfect. Those who are trying to become
                          better programmers will react to criticisms of their code in a positive
                          way.

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

                          • jacob navia

                            #14
                            Re: What am I doing wrong?

                            Richard Heathfield wrote:
                            jacob navia said:
                            >
                            >Richard Heathfield wrote:
                            >>
                            >Perhaps Mr Navia would be so kind as
                            >>to point out where CU claims that pointers are always 32 bits?)
                            >Specifically in Chapter 11, page 353 you assume
                            >sizeof pointer is equal to sizeof int...
                            >
                            [snip]
                            And the bug that /is/ there was documented on
                            the errata page in November 2000.
                            >
                            >
                            Right.

                            So please stop making fun of people when they have a bug.

                            And here in this same group I have pointed several bugs in code
                            you posted, so just be kind with others when they have a bug.


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

                            Comment

                            • Keith Thompson

                              #15
                              Re: What am I doing wrong?

                              jacob navia <jacob@nospam.c omwrites:
                              Richard Heathfield wrote:
                              >
                              Perhaps Mr Navia would be so kind as
                              >to point out where CU claims that pointers are always 32 bits?)
                              >
                              Specifically in Chapter 11, page 353 you assume
                              sizeof pointer is equal to sizeof int...
                              >
                              It will work when sizeof pointer is equal to sizeof int
                              (windows or linux 32 bit versions) but will crash when
                              sizeof int != sizeof pointer (windows 64 bits.
                              >
                              I would never mind that you have a bug. What bothers me
                              is how you make fun of other people when they try to
                              write something and have a bug!
                              >
                              This slightly ironic tone, this "dettached" viewpoint,
                              as you never make those kind of errors.
                              I would never mind that *you* have a bug. What bothers me is when you
                              treat bug reports as personal attacks. I have never seen Richard do
                              this; I see you do it over and over again.

                              And you don't seem to understand the difference.

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

                              Working...