tags:

views:

91

answers:

2

I direct you to Kernighan & Ritchie exercise 7.1

Write a program that converts upper case to lower case or lower case to upper case depending on the name it is invoked with,...

How can I invoke the same program with different names?

I am using Linux, so I am invoking a compiled program just by entering:

$./a.out

What should I be doing differently?

+8  A: 

You should create a symbolic link, or just copy the executable of course:

Either

$ ln -s a.out A.out

or

$ cp a.out A.out

Then in your program's main(), inspect argv[0] to figure out how to act. This is a pretty useful technique, actually used often by production software.

unwind
Just copy the file, of course. Never thought it would just be so simple! Don't I feel stupid. Thanks
Tom
Don't forget the choice of using a *hard* link: `ln a.out A.out`. Better than either a copy or a symbolic link because it expresses you exact intention: give one file two names.
dmckee
@dmckee: True, I guess. I never use hard links myself, but sure.
unwind
+2  A: 

You could just copy it to a different file:

cp a.out myprogram1
cp a.out myprogram2

Wallah, your program has different names.

Daniel Bingham
+1 for Wallah, never knew how that was spelt before
Patrick
thanks. just didn't think about the obvious solution!
Tom
@patrick Not sure I'm spelling it right - just took a guess and went with it ;)
Daniel Bingham
Voilà is technically the correct spelling. It is French for, basically, "There it is..."
Jacob G
Oh, I wasn't thinking of the voila, more of a trumpet sort of sound
Patrick
God, what a pointless comment, let's add another one
Patrick
@Jacob Thanks :) Learn something new every day. I'd always thought that Voila was pronounced more like Viola and was completely different than whallah or wallah. Guess that's what I get for reading too much ;)
Daniel Bingham
Copying the files you have to maintain two versions that's why links are a much better option.
dtmilano