Re: I need some ideas on how to go about creating files....



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?
.



Relevant Pages

  • Re: I need some ideas on how to go about creating files....
    ... creates an input file. ... the source code and recompile it everytime they want to change the ... use standard shell facilities to make it work with different files, ... The at the bash prompt, ...
    (comp.unix.programmer)
  • Re: what is wrong with this code?can someone walk me through this?
    ... particle in a low reynolds number flow. ... compilers, I have a working version of this code, but it doesnt work ... with the input file and see for what values of input the stokes number ... Is this fixed format or free format source code? ...
    (comp.lang.fortran)
  • Re: I need some ideas on how to go about creating files....
    ... creates an input file. ... the source code and recompile it everytime they want to change the ... I guess it's time for me to crack out "Unix Programming for ... minimum wage clerks that got rejected twice by UC-Berkeley." ...
    (comp.unix.programmer)
  • Re: I need some ideas on how to go about creating files....
    ... creates an input file. ... the source code and recompile it everytime they want to change the ... I'm not too sure how I would go about this using environment ... minimum wage clerks that got rejected twice by UC-Berkeley." ...
    (comp.unix.programmer)
  • Re: Link warning and error, what do they mean?
    ... Okay, for anybody that cares... ... I don't know why the compiler didn't tell me it couldn't ... find the source code, but it couldn't, and then tried to use the input file ...
    (microsoft.public.vc.ide_general)