Howdy, Stranger!

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

Categories

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.

readln(record.field);

Mr. El MoeMr. El Moe Posts: 2Member
Here is some sample code... but I get an error and it's been too long since I've delt with records to figure what I'm doing wrong.


[B]Type[/B]
..rooms = [B]Record[/B]
....name : [B]String[20][/B];
....descpt1, descpt2 : [B]String[/B];
..[B]end[/B];

[B]Var[/B]
..fname : [B]file[/B];

[B]Begin[/B]
..assign(fname, 'rooms.dat');
..readln(rooms.name); [Red][Italic]<---- This is were I get my error, it says it is expecting a '(' after the word 'rooms'. I'm attempting to read input to store into rooms.name... what's going on here?? What am I missing?[/Italic][/Red]
[B]end[/B];


Any help will be appreciated... thanks!

Mr. El Moe

Comments

  • DexterMagnificDexterMagnific Posts: 35Member
    : Here is some sample code... but I get an error and it's been too long since I've delt with records to figure what I'm doing wrong.
    :
    :
    : [B]Type[/B]
    : ..rooms = [B]Record[/B]
    : ....name : [B]String[20][/B];
    : ....descpt1, descpt2 : [B]String[/B];
    : ..[B]end[/B];
    :
    : [B]Var[/B]
    : ..fname : [B]file[/B];
    :
    : [B]Begin[/B]
    : ..assign(fname, 'rooms.dat');
    : ..readln(rooms.name); [Red][Italic]<---- This is were I get my error, it says it is expecting a '(' after the word 'rooms'. I'm attempting to read input to store into rooms.name... what's going on here?? What am I missing?[/Italic][/Red]
    : [B]end[/B];
    :
    :
    : Any help will be appreciated... thanks!
    :
    : Mr. El Moe
    :

    Your problem is that you've declared a type called rooms, but you've not
    declared a variable based on that type.
    Pascal works with variables only.

    TYPE Rooms = RECORD
    Name, Descrpt1, Descrpt2 : STRING;
    END; { of type declaration}

    Now you should declare variable based on that type :

    VAR MyRoom : Rooms;

    BEGIN
    Assign(FName, 'rooms.DAT');
    Reset(FName);
    ReadLN(FName, MyRoom);
    {reads the entire record from file}
    END.
Sign In or Register to comment.