Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.pascal.borland    |    Borland Pascal was actually pretty neat    |    2,978 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,816 of 2,978    |
|    Wolf Behrenhoff to marktyers    |
|    Re: Arrays of Strings - problem    |
|    07 Sep 10 00:24:05    |
      e0d61fb5       From: nospampleasebutthisisvalid3@gmx.net              On 06.09.2010 23:25, marktyers wrote:       > The challenge was to read a text file in a line at a time (csv       > format). extract the last (third) value on each line and add these up.       > The text file contained the following:       >       > fuel,SMITH,55.99       > accomodation,SMITH,28.50       > food,SMITH,12.99       > food,JONES,18.50       > books,JONES,5.99       > accomodation,SMITH,55.68       > books,SMITH,24.98       >       > A Python version of the code to solve this looks like:              Yes, for this type of task Python and/or Perl are great. I would       probably use:       $ perl -E'$sum+=(split/,/)[2] while <>;say "Sum is $sum"'              > My Pascal code looks like this:       >       > program fileread(output);        ^^^^^^ not needed.              > uses       > sysutils;       > var       > fp : Text;       > line : String[30];              If you are using String[30] then you have "old style" Turbo Pascal       strings, i.e. line[0] contains the length of the string (also known as       ShortString in FPC). Why limit the length to 30? Just just String (and       switch on default usage of "Delphi style" strings, i.e. $H+) or use       AnsiString.              > else begin       > items[wordnum][place] := line[i];              Here you set the place-th char of word wordnum to line[i]. But that does       not update the length of the string! It is even wrong code if the string       has less chars than place. Simply use normal string concatenation       (string:=string+character;).              In C this might work if the whole string is filles with zeroes       beforehand as C determines the length using the null byte.              > Pascal does not seem to have any prebuilt function for this so I       > had to write my own algorithm.              You might want to have a look at the documentation of TStrings and       TStringList :-)              - Wolf              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca