adamsd@handel.colostate.edu (daniel joseph adams) (03/17/89)
I have a question, is there an _easy_ way to allow the user to input there own name for an external file? Is there anyway to get around declaring the external file in the program parameters? I know I can use reset to 'connect' files, but how can I not declare the name of the file in the program parameters if I don't know what name the user is going to name his file?
abcscnuk@csuna.csun.edu (Naoto Kimura) (03/19/89)
In article <1436@ccncsu.ColoState.EDU> adamsd@handel.colostate.edu.UUCP (daniel joseph adams) writes: > > I have a question, is there an _easy_ way to allow the user to input >there own name for an external file? > > Is there anyway to get around declaring the external file in the program >parameters? I know I can use reset to 'connect' files, but how can I not >declare the name of the file in the program parameters if I don't know what >name the user is going to name his file? > This really depends upon the compiler. Some versions of pascal will allow you to associate a file variable with an external file by using an 'assign' procedure, while others use 'reset.' Some versions of pascal don't allow you to do this and require you to set up the associations through the operating system, either by performing the appropriate FILEDEFs before you run the program or by specifying the files at runtime when you execute the program. On the VM/CMS system that I used at UCLA, I wrote an EXEC (basically a shell program) to set up the FILEDEFs before I ran my programs. If I recall correctly, to do this (associate the file variables with external files) at runtime within your program, I had to use a system call to do it. The Pascal6000 compiler on the Cyber here sets up the file associations when you invoke the executable. The files variables are associated with filenames you specify on the command line. For example, if you had the program header "program ugh(input,output,data);" and you executed the program by typing "LGO,,F1,F2." at the system prompt ( 'LGO' is the default name of the executable file created by the compiler -- it stands for Load and GO ), the file variable 'input' would be associated with the external file 'INPUT' (usually the terminal) and file variable 'output' would be associated with the external file 'F1' and the file variable 'data' will be associated with the external file 'F2.' Because Pascal was originally designed on a batch processing system, I/O is somewhat strange as you may already know (like knowing the end of file or end of line status before any read is performed -- which is somewhat strange when you want interactive I/O). With some compilers, it is difficult to make your program generic enough to work either interactively or as a batch process. If you compile in the usual manner, you will have to enter the data before you are prompted for it. If you compile for interactive I/O you can get strange behavior when you associate an external file with the standard input and output file variables (they either don't get associated with the external files or you will end up losing the first character or line of input). //-n-\\ Naoto Kimura _____---=======---_____ (abcscnuk@csuna.csun.edu) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!