home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!warwick!uknet!nplpsg!news
- From: KDT@newton.npl.co.uk (K D TART CSU BLDG. 93)
- Newsgroups: comp.lang.pascal
- Subject: Re: ??????? User input of textfile to read ?????????
- Message-ID: <1992Nov23.113554.16785@psg.npl.co.uk>
- Date: 23 Nov 92 11:35:54 GMT
- References: <1en55vINN1u4@cumin.csv.warwick.ac.uk>
- Sender: news@psg.npl.co.uk (Network News Administration)
- Distribution: uk
- Organization: National Physical Laboratory, UK
- Lines: 63
- In-Reply-To: cstaddc@csv.warwick.ac.uk's message of 22 Nov 92 05: 17:50 GMT
- Nntp-Posting-Host: newton
- X-News-Reader: VMS NEWS 1.21
-
- > Hi, I'm just getting to grips with pascal and have a niggling problem.
- > I want to read in a filename using say :
- >
- > writeln(' Enter filename to read ');
- > readln(filename);
- >
- > and take characters in from the specified file using :
- >
- > reset(filename)
- >
- > Naturally filename must be of type : text. This clashes with the first step
- > where I assigned the name of the file to filename !!!
- >
- > i.e. the variable filename must be :
- >
- > packed array (* to hold filename *)
- > file of text. (* to access contents of file *)
- >
- >
- > Can anyone suggest a way around this problem or maybe a new approach to
- > achieve the same result.
-
- You need to have 2 variables, one for the filename and the other for the file
- itself. The filename variable needs to be some sort of string type or packed
- array, and the variable for the file needs to be type TEXT.
-
- eg.
-
- var
- myfile :text;
- filename :packed array [1..80] of char;
-
-
- begin
- write ('Filename: ');
- readln (filename);
-
- { You need some command in here to link the MYFILE variable with the external
- file whose name is in FILENAME. This will depend on the version of Pascal
- you are using because standard Pascal does not cater for this. See * below }
-
- reset (myfile);
- read (myfile, anotherstringtypevariable);
-
- { ... and so on }
- end.
-
-
- * in Turbo Pascal, you should declare FILENAME as a string and use the ASSIGN
- command to link your file variable with the external file:
-
- ASSIGN (myfile, filename);
- RESET (myfile);
-
- In VAX pascal, you need to do OPEN:
-
- OPEN (myfile, filename, readonly);
- RESET (myfile);
-
- You need to specify the type of Pascal you are using to get a more complete
- answer.
-
- Kingsley.
-