Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > "HelloWorld.c" Won't Work in C, why not?

"HelloWorld.c" Won't Work in C, why not?
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 1999
Location: NY
Status: Offline
Reply With Quote
May 26, 2001, 01:36 PM
 
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
Reply With Quote
May 26, 2001, 01:56 PM
 
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
Reply With Quote
May 26, 2001, 01:58 PM
 
Try this:

./a.out
     
Fresh-Faced Recruit
Join Date: Mar 1999
Location: NY
Status: Offline
Reply With Quote
May 26, 2001, 08:20 PM
 
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
Reply With Quote
May 26, 2001, 10:21 PM
 
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
Reply With Quote
May 27, 2001, 04:40 AM
 
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
Reply With Quote
May 27, 2001, 08:34 AM
 
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
Reply With Quote
May 27, 2001, 01:42 PM
 
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
Reply With Quote
Jun 1, 2001, 08:31 AM
 
Ick...you guys are using a.out? Please.

cc -o HelloWorld HelloWorld.c
./HelloWorld

Ahhhhhhhhh...much nicer.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:15 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2