4

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

Michael
  • 462
  • 1
  • 6
  • 18

3 Answers3

3

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)

Community
  • 1
  • 1
Pete
  • 10,310
  • 7
  • 53
  • 59
  • The prefix "./" *is* important, at least on Linux, as the current folder "." is usually not part of the PATH variable, thus the system won't find the binary. If the executable you produced has the same name as a standard program on you system (like "test") leaving out "./" will use the system program, not the one you compiled. – bluebrother Aug 01 '09 at 19:36
  • You misunderstand what I said. I did /not/ say "It doesn't matter whether or not you prefix with "./"... I was simply pointing out exactly what you said: If you prefix with "./", there wont be a naming clash with find & test. – Pete Aug 01 '09 at 20:19
  • @Pete, thanks for slurping in the answers that others provided. First with the name clash with the system command find and then with the use of ./ to dereference. Check the edits ladies and gents... – Rob Wells Aug 02 '09 at 00:31
  • actually by "others" I really meant my answer and my edits to clarify! – Rob Wells Aug 02 '09 at 00:36
1

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!

Rob Wells
  • 36,220
  • 13
  • 81
  • 146
0

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 ?

blacky
  • 41
  • 2