home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6863 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  2.3 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!nplpsg!news
  2. From: KDT@newton.npl.co.uk (K D TART CSU BLDG. 93)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: ???????  User input of textfile to read ?????????
  5. Message-ID: <1992Nov23.113554.16785@psg.npl.co.uk>
  6. Date: 23 Nov 92 11:35:54 GMT
  7. References: <1en55vINN1u4@cumin.csv.warwick.ac.uk>
  8. Sender: news@psg.npl.co.uk (Network News Administration)
  9. Distribution: uk
  10. Organization: National Physical Laboratory, UK
  11. Lines: 63
  12. In-Reply-To: cstaddc@csv.warwick.ac.uk's message of 22 Nov 92 05: 17:50 GMT
  13. Nntp-Posting-Host: newton
  14. X-News-Reader: VMS NEWS 1.21
  15.  
  16. >     Hi, I'm just getting to grips with pascal and have a niggling problem.
  17. > I want to read in a filename using say :
  18. >     writeln(' Enter filename to read ');
  19. >     readln(filename);
  20. > and take characters in from the specified file using :
  21. >     reset(filename)
  22. > Naturally filename must be of type : text.  This clashes with the first step
  23. > where I assigned the name of the file to filename !!!
  24. >     i.e.   the variable filename must be :
  25. >  
  26. >      packed array (* to hold filename *)
  27. >      file of text.  (* to access contents of file *)
  28. >     Can anyone suggest a way around this problem or maybe a new approach to
  29. > achieve the same result.
  30.  
  31. You need to have 2 variables, one for the filename and the other for the file
  32. itself. The filename variable needs to be some sort of string type or packed
  33. array, and the variable for the file needs to be type TEXT.
  34.  
  35. eg.
  36.  
  37. var
  38.   myfile :text;
  39.   filename :packed array [1..80] of char;
  40.  
  41.  
  42. begin
  43.   write ('Filename: ');
  44.   readln (filename);
  45.  
  46.   { You need some command in here to link the MYFILE variable with the external
  47.     file whose name is in FILENAME. This will depend on the version of Pascal
  48.     you are using because standard Pascal does not cater for this. See * below }
  49.  
  50.   reset (myfile);
  51.   read (myfile, anotherstringtypevariable);
  52.  
  53.   { ... and so on }
  54. end.
  55.  
  56.  
  57. * in Turbo Pascal, you should declare FILENAME as a string and use the ASSIGN
  58.   command to link your file variable with the external file:
  59.  
  60.        ASSIGN (myfile, filename);
  61.        RESET (myfile);
  62.  
  63.   In VAX pascal, you need to do OPEN:
  64.  
  65.        OPEN (myfile, filename, readonly);
  66.        RESET (myfile);
  67.  
  68.   You need to specify the type of Pascal you are using to get a more complete
  69.   answer.
  70.  
  71.     Kingsley.
  72.