home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!netnews!bandy
- From: bandy@netnews.jhuapl.edu (Mike Bandy)
- Subject: Re: DEC VMS VERSION OF C - HOW TO ASSIGN FILE NAME?
- Message-ID: <BxC0AB.GvA@netnews.jhuapl.edu>
- Organization: JHU/Applied Physics Laboratory
- References: <92310.16240634R33O7@CMUVM.CSV.CMICH.EDU>
- Date: Sat, 7 Nov 1992 05:51:47 GMT
- Lines: 43
-
- Robert A Rawlinson <34R33O7@CMUVM.CSV.CMICH.EDU> writes:
-
- >I HAVE A COUPLE OF STUDENTS DOING SOME C PROGRAMING FOR ME. I AM NOT A
- >GOOD C PROGRAMER SO I COULD NOT SEEM TO FIND THE ANSWER IN THE MANUALS.
- >IN COBOL I CAN CODE A FILE NAME AND THEN WHEN I RUN THE PROGRAM I CAN
- >ASSIGN A FILE NAME AND DIRECTORY. MY STUDENTS CODE IN C AND INDICATED THE
- >FILE AND DIRECTORY HAVE TO BE HARD CODED. I SUSPECT THERE IS A WAY TO
- >USE A NAME THAT I COULD ASSIGN A FILE AND DIRECTORY TO LATER AS IN COBOL.
- >COULD SOMEONE POINT ME IN THE CORRECT DIRECTION TO SOLVE THIS?
- >THANKS
- >BOB
-
- File handling as you require is not part of the C or Cobol RTL but built into
- the operating system. Use a logical name in your program, let's call it FOO.
- Then you open FOO using the fopen routine:
- fd=fopen("FOO","r");
- FOO is now hardcoded into the program -- but from DCL you can point FOO anywhere
- you want using the DEFINE verb (or use ASSIGN if you'd rather). Like:
- $ DEFINE FOO DISK$USER1:[DIR1]FILE1.XXX
- Run your program against FILE1.XXX
- $ DEFINE FOO DISK$USER2:[DIR99]FILE99.XXX
- Run your program against FILE99.XXX
-
- You also have the option of passing the file name on the command line using
- the parameters on main(). For example, code your C routine like:
- main(int argc, char **argv)
- Then the filename is retrieved using argv[1] (check argc to be sure that it's
- at least 2).
-
- This requires you to create a local symbol from DCL for the program prior
- to it's execution. Like this:
- $ MYUTIL :== $MYDISK:[MYDIR]MYPROG
-
- Then run it like:
- $ MYUTIL DISK$USER12:[DIR21]FILE21.XXX
-
-
-
- --
-
- Mike Bandy
- bandy@aplcomm.jhuapl.edu
- Johns Hopkins University / Applied Physics Lab
-