#1
  1. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18

    Pascal string problem


    I have made a program that opens files. Nothin' spectacular. The problem is that if the text is more then 255 characters long, the rest of the text isn't read. So I want it to open up a new string and write the rest in that string, but I dont know how. This is how far I've gotten.
    Code:
    program bootstat2;                {™ppnar bootstat.dat}
    uses
      crt;
    var
      s, t, u : string;
      f, w, q : text;
      a, L : integer;
    begin
      clrscr;
      write('Skriv in filnamnet:');
      readln(t);
      assign(f, t);
      assign(w, 'C:logg.txt');
      assign(q, 'C:logg2.txt');
      rewrite(q);
      reset(f);
      rewrite(w);
      readln(f,s);
      L := length(s);
      writeln(s);
      writeln(w,s);
        for a := 1 to L do begin
          readln(f,s);
          writeln(s);
          writeln(w,s);
        end;
        if L+1 > 255 then begin
          for a := L to (2*L) do begin
          readln(f,u);
            writeln(u);
            writeln(q,u);
          end;
        end;
      close(q);
      close(w);
      close(f);
      writeln();
      writeln('En loggfil har skapats. Den heter "logg.txt". Tryck ENTER.');
      readln();
    end.
  2. #2
  3. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    255 is the max length of a string in pascal. you need to read in chunks of up to 255 bytes at a time.

    I think it can be done with the read function, but my pascal is REALLY rusty, so you'll want to check on that
  4. #3
  5. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    Okay, I'll see what I can make from that, thx
  6. #4
  7. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    I worked it out. This is the way to do it. Can't belive I missed it before
    Code:
    program openup;              {By lingon}
    uses
      crt;
    var
      s, t : string;
      f, p : text;
    begin
      clrscr;
      write('Enter filename:');
      readln(t);
      assign(f,t);
      assign(p,'logg.txt');
      reset(f);
      rewrite(p);
      while not eof(f) do begin
        readln(f,s);
        writeln(s);
        writeln(p,s);
      end;
      close(f);
      close(p);
      writeln();
      writeln('A loggfile has been created. Press ENTER.');
      readln();
    end.
  8. #5
  9. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    I'd look at using more meaningful variable name especially for when you start creating longer programs ... just a nod

    Comments on this post

    • netytan agrees : Always a good idea :)
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  10. #6
  11. C++arl!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Location
    Stockholm
    Posts
    165
    Rep Power
    18
    Will do, thanks

IMN logo majestic logo threadwatch logo seochat tools logo