 |
 |
"HelloWorld.c" Won't Work in C, why not?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 1999
Location: NY
Status:
Offline
|
|
I wrote something using emacs more complex than HelloWorld, but that didn't work. Then I wrote HelloWorld.c to make sure I wasn't going insane. But, after I compiled my basic C program and got "a.out", I couldn't run the program. Why not?
Thanks in advance.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status:
Offline
|
|
I'm guessing because the current path is not in your environment variable.
Try
./a.out
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 1999
Location: NY
Status:
Offline
|
|
Thanks for your assistance. It worked. But, my question is why do I have to do type "./"? If I am at the same directory level as the application and I call it, I figured it should work. Someone please explain to me and if it requires changing my shell setup, please advise.
Thanks again.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: Fort Worth, TX, USA
Status:
Offline
|
|
zeroKewl: I believe the reason Unix systems don't usually include . in their path is the following: when you type "ls", for example, you expect the system to run /bin/ls. But, consider what would happen if someone was to put a program in a publically accessible folder called "ls"... then, if you were in that directory and typed "ls", the system might run that version, which could potentially have malicious code.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
This has been explained in detail before all over the place. I suggest you get a good shell reference and/or just a general UN*X reference book and read through that 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 1999
Location: NY
Status:
Offline
|
|
I just want to add that when I was back at school, UNIX, Solaris I believe, was the primary OS. Every one of us had to write programs and we would just compile it and then run it when we were in that directory. I, then, ask how that was set up. Regardless, thank you all for your help and explanations.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
You need to set your PATH variable to include the current directory which is represented with a period or you can create a folder "Code" for for specific C coding and then add that folder to your PATH variable in your .cshrc file -assuming that you are using the default tcsh.
set path=($path /Users/YourLoginName/Code)
all you have to do next is restart your terminal or source the edited .cshrc.
When you where in school, your system administrator had you login files setup appropriately for your needs. You should be fine on MacOS X, but echoing the above, you do need a good Unix book.
[This message has been edited by DaGuy (edited 05-27-2001).]
|
|
iMac 17" G4 800MHZ & 768 SDRAM
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: May 2001
Status:
Offline
|
|
Ick...you guys are using a.out? Please.
cc -o HelloWorld HelloWorld.c
./HelloWorld
Ahhhhhhhhh...much nicer.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|