• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Did program suggested, but get type mismatch

I did the program that sumant gave, but I'm having problems.
http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10302613 


I get a write mismatch error on this line:

write(male, name);
0
kazooie21
Asked:
kazooie21
  • 3
  • 3
  • 2
  • +1
1 Solution
 
kazooie21Author Commented:
I guess that's what he means when he says; "Use the correct open file"

re....(male)

etc.
0
 
dbruntonCommented:
write(male, customer.name);

name is inside the record customer
0
 
Alisher_NCommented:
this old question's comments are not available for free anymore ;-) so I can't see a source, but if you use 'male' file in 'write' procedure you have to open it first, so
var
  male : text; {must be declared if you use text files}
begin
  assign( male, 'somefile.txt' );    { file name must be assigned to variable }
 rewrite( male )  {to create new file, or use append( male ) if you want to add to existing}

you can not use reset(male) because file will be opened as readonly !


0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
dbruntonCommented:
type customer = record
  name : as a string;
  address : as a string;
  gender : char;
  balance : real;
end;
     

I can.  There's too much code to post here but.

He has a record structure in which name is a field of the record.
Male is a text file as you surmise.
0
 
dbruntonCommented:
Whoops!  Reread the original program.


kazooie21

How do you open the files?  As text files or record files as sumant posted.  If  you used sumant's code which uses records then you should use

write(male, customer);

You must write the whole record at once to the file.  This would explain the type mismatch.

If they are text files then my code should be correct.
0
 
sumant032199Commented:
Yes, you must write entire record at once. Do not go for text files, They occupy  larger space and binary files work always work fine and fast.
0
 
kazooie21Author Commented:
I did the assign(male, somefile.txt') thing, but I still get the same error.
0
 
Alisher_NCommented:
kazoo! check again how your file is declared...
if it is

var
  malefile : customer;
  myrecord : customer;
{then you have to use}
begin
  assign( malefile, 'somefile.dat' );
  rewrite( malefile, 1 );
  myrecord.name := 'lastname';
  blockwrite( malefile, myrecord, sizeof( cutomer ));
  close( malefile );

another option when you declare file as Text:

var
  malefile : Text;
  myrecord : cutomer;
begin
  assign( malefile, 'somefile.dat' );
  rewrite( malefile ); { no record size!}
  myrecord.name := 'lastname';
  writeln( malefile, myrecord.name );
  close( malefile );
end.

you can not mix two these approaches!

0
 
Alisher_NCommented:
BTW, first approach much better - avoid to use text files unless you going to edit them manually...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now