Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.