Question

I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist.

`gcc -o find find.c

open find test

The file /Documents/Learning_C/test does not exist.`

Any suggestions? Thanks

Was it helpful?

Solution

What system are you on? In Unix/Linux you compile & run your executable via:

gcc -o find find.c
./find test

As others have noted, when you prefix your binary with "./", there wont be any naming conflicts. However, if you made find accessible in your $PATH, you might have some conflicts with find and test--standard programs with most *nix distributions... Maybe you could choose more specific names (i.e. ./myFind testArg)

OTHER TIPS

Try giving your output executable a different name.

I suspect your executing the system find command which is looking for a directory called 'test'.

Or try forcing it by executing

./find toto

Edit: Prepending the ./ to the command is important because it tells the shell to execute the find in the current directory as opposed to the first 'find' that exists in your PATH. It is normally recommended that you don't have . (the current directory) in your PATH for security reasons.

HTH

P.S. Forgot to say good one for working through K&R. I just finished doing the same after working in C for thirty years and it was good to get back and refresh the mind!

Instead of making us all individually guess what exactly you're doing wrong, perhaps you should paste the program you're using for the illustration mentioned ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top