Re: I need some ideas on how to go about creating files....
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Fri, 29 Jun 2007 10:37:23 +0200
K-mart Cashier <cdalten@xxxxxxxxx> writes:
On Jun 28, 7:32 pm, Eric Sosman <esos...@xxxxxxxxxxxxxxxxxxx> wrote:
K-mart Cashier wrote:
Program A reads in a file. However, Program A dictates the the person
creates an input file. After the person creates the file, they have to
change the following lines to the path of the file they created.
#define PATH "/home/calten/run/data"
Now, there has to be some better way than just having the user edit
the source code and recompile it everytime they want to change the
file name.
I'm sure there is something pretty obvious that I missed. Ideas?
Input redirection, command-line arguments, environment
variables, prompt-and-response, ...
[...]
I'm not too sure how I would go about this using environment
variables. I guess it's time for me to crack out "Unix Programming for
minimum wage clerks that got rejected twice by UC-Berkeley."
Generally, the answer is 'use some form of parameter passing' instead
of compiled-in values. The usually simplest way is to design the
program as a so-called 'filter', meaning it reads from STDIN_FILENO (0,
"stdin") and writes to STDOUT_FILENO (1, "stdout). The user can then
use standard shell facilities to make it work with different files, eg
./the_program </path/to/input/file >/path/to/output/file
Since the shell already knows how to open named files, why duplicate
code doing so in a program for no particular reason?
.
- Follow-Ups:
- Re: I need some ideas on how to go about creating files....
- From: K-mart Cashier
- Re: I need some ideas on how to go about creating files....
- References:
- I need some ideas on how to go about creating files....
- From: K-mart Cashier
- Re: I need some ideas on how to go about creating files....
- From: Eric Sosman
- Re: I need some ideas on how to go about creating files....
- From: K-mart Cashier
- I need some ideas on how to go about creating files....
- Prev by Date: Re: How to check for stuff like '|'
- Next by Date: Re: execv
- Previous by thread: Re: I need some ideas on how to go about creating files....
- Next by thread: Re: I need some ideas on how to go about creating files....
- Index(es):
Relevant Pages
|