Designating input and output files in the command line of an executable file
Posted on 2004-03-26
I have written a program which inputs data from an input file and outputs the resultant solution to an output file. Currently I have the file names hard coded in the body of the program. I need to know how I can enable the program to read from and write to data files of different names which will be supplied by users in the input line of the program executable call. Ideally, I would like to have generic names coded in the program so that they can be associated with the input and output files so many different files can be used.
An example would be:
./program_utilization.exe inputfile outputfile errorfile
Now the user would call the program by issuing the following command:
./program_utilization.exe myinputfile myoutputfile myerrorfile
The program should be able to associate all of the file commands to inputfile/outputfile/errorfile written in the program with the user specified myinputfile/myoutputfile/myerrorfile so that each user would have distinct input and output file names and this process then would enable multiple users at the same time.
I'm not sure how to code this in C. I need to scan the names after the executable call and have them designated as the different files depending on their position and then associated with wildcards written into the program.
Any help would be appreciated.