Exercise 7-1. Write a program that converts upper case to lower or lower case to upper, depending on the name it is invoked with, as found in argv[0].
For those of you interested in writing the program, you can find sample solutions here: http://users.powernet.co.uk/eton/kandr2/krx701.html
My question, however, is exactly how do you invoke the program? argv[0] refers to the name of the program, but along with the program’s filepath in addition. When I do a printf() on argv[0], it outputs the full path from /home if I run the program via my code::blocks IDE. If I try to execute the program via the command line with ‘./upper’ (without quotes), argv[0] includes the ‘./’ before the program name.
Is there anyway to invoke this program WITHOUT adding the program path to the PATH environment variable?
You can compile it once, whatever the output filename (e.g.:
my_c_program) and withbash, use:If you want it to run in a separate shell:
Basically, the syntax is
exec -a <newname> <command>, where<newname>will beargv[0].