Solved

Did program suggested, but get type mismatch

Posted on 2000-03-08
9
164 Views
Last Modified: 2010-04-16
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
Comment
Question by:kazooie21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 

Author Comment

by:kazooie21
ID: 2598057
I guess that's what he means when he says; "Use the correct open file"

re....(male)

etc.
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2599538
write(male, customer.name);

name is inside the record customer
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599552
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 48

Expert Comment

by:dbrunton
ID: 2599806
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
 
LVL 48

Expert Comment

by:dbrunton
ID: 2599836
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
 
LVL 3

Expert Comment

by:sumant032199
ID: 2601741
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
 

Author Comment

by:kazooie21
ID: 2602889
I did the assign(male, somefile.txt') thing, but I still get the same error.
0
 
LVL 3

Accepted Solution

by:
Alisher_N earned 5 total points
ID: 2603813
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
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2603827
BTW, first approach much better - avoid to use text files unless you going to edit them manually...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question