We help IT Professionals succeed at work.

Did program suggested, but get type mismatch

kazooie21
kazooie21 asked
on
197 Views
Last Modified: 2010-04-16
I did the program that sumant gave, but I'm having problems.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10302613 


I get a write mismatch error on this line:

write(male, name);
Comment
Watch Question

Author

Commented:
I guess that's what he means when he says; "Use the correct open file"

re....(male)

etc.
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT

Commented:
write(male, customer.name);

name is inside the record customer
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 !


dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT

Commented:
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.
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT

Commented:
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.
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.

Author

Commented:
I did the assign(male, somefile.txt') thing, but I still get the same error.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
BTW, first approach much better - avoid to use text files unless you going to edit them manually...
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.