WRITING TO A FILE - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

WRITING TO A FILE

HELP!!! I NEED THE CODE TO WRITE AN ARRAY (OF UPTO 100 NUMBERS) TO A FILE.


I ALSO NEED THE CODE TO READ NUMBERS FROM A FILE, SORT LEM INTO ASSENDING ORDER AND WRITE THEM TO ANOTHER FILE


ANY HELP WOULD BE MUCH APPRECIATED.


Comments

  • : HELP!!! I NEED THE CODE TO WRITE AN ARRAY (OF UPTO 100 NUMBERS) TO A FILE.


    : I ALSO NEED THE CODE TO READ NUMBERS FROM A FILE, SORT LEM INTO ASSENDING ORDER AND WRITE THEM TO ANOTHER FILE


    : ANY HELP WOULD BE MUCH APPRECIATED.




    here is an example. The Array should be stored in a TStringList. It makes it easy to deal with. Secondly, I don't remember if it's FileClose (f) or CloseFile (f). When I write to files, I always have to look it up.




    var

    i: Integer;

    s: String;

    f: TextFile;

    YourArray: TStringList;


    begin

    YourArray := TStringList.Create;

    YourArray.Add ('blah');

    AssignFile (f, 'c: est.txt');

    Rewrite (f);

    for i := 0 to YourArray.Count-1 do

    begin

    WriteLn (f, YourArray[i]);

    end;

    FileClose (f);

    YourArray.Free;

    end;









  • : HELP!!! I NEED THE CODE TO WRITE AN ARRAY (OF UPTO 100 NUMBERS) TO A FILE.


    : I ALSO NEED THE CODE TO READ NUMBERS FROM A FILE, SORT LEM INTO ASSENDING ORDER AND WRITE THEM TO ANOTHER FILE


    : ANY HELP WOULD BE MUCH APPRECIATED.


    Here's an easier example...


    program Example;


    uses Crt;


    var f: file of integer;

    a1: array[1..10] of integer;

    i1: integer;


    begin

    {Write to file}

    assign(f,'EXAMPLE.INT');

    rewrite(f);

    for i1:= 1 to 10 do write(f,a1[i1]);

    close(f);

    {Read from file}

    assign(f,'EXAMPLE.INT');

    reset(f);

    i1:= 1;

    while not eof(f) and (i1 < 10) do

    begin

    read(f,a1[1]);

    inc(i1);

    end;

    close(f);

    end.


    Hope you can do soemthing with it... If you need more info, mail me


    SHoGuN


Sign In or Register to comment.