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 > Mac OS X > Hello World not displaying

Hello World not displaying
Thread Tools
Fresh-Faced Recruit
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 26, 2003, 12:49 PM
 
I'm just playing around with gcc compiler in 10.3.

Here is my code:

#include <stdio.h>

main(){

printf("Hello, World!");
}


Here are my commands:

gcc test.c -o test

I'm editing my file commandline through pico


It compiles fine(It better!) but doesn't display anything when I run test. Any idea what I'm doing wrong?

Thank you
     
Mac Enthusiast
Join Date: Jul 2002
Status: Offline
Reply With Quote
Oct 26, 2003, 01:35 PM
 
When you execute "test", you're running /bin/test, a standard utility. Try executing "./test" instead.
     
Fresh-Faced Recruit
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 26, 2003, 02:57 PM
 
Thank you very much!

Is there any way to avoid this? How can I make it where I would just run the executable I assign without ./ ?
     
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Oct 26, 2003, 03:38 PM
 
Your $PATH variable determines where the interactive shell finds files to execute. By default $PATH is /bin /sbin /usr/bin /usr/sbin. I added a folder to my HOME directory named bin and added /Users/craig/bin to my path by modifying the .tcshrc file in 10.2 and the .bashrc file in 10.3. Do a Google search on tcsh path is your are using 10.2 and bash path if your are using 10.3. There will be examples of what to do on several sites listed there.

HTH
Craig
     
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Oct 26, 2003, 04:34 PM
 
Originally posted by ownersbox:
Thank you very much!

Is there any way to avoid this? How can I make it where I would just run the executable I assign without ./ ?
Yes is is possible using the aforementioned PATH variable but it is highly recommended that you don't make such a change.
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Oct 27, 2003, 11:47 AM
 
Originally posted by WJMoore:
Yes is is possible using the aforementioned PATH variable but it is highly recommended that you don't make such a change.
Just give your executable a unique name. Call it HelloWorld instead of test.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Fresh-Faced Recruit
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 27, 2003, 11:49 AM
 
Tried that, it is still looking in the bin.... I will just use ./ to avoid causing other issues
     
Fresh-Faced Recruit
Join Date: Oct 2003
Status: Offline
Reply With Quote
Oct 27, 2003, 02:37 PM
 
You can add '.' (the current working directory) to the PATH, but it is not recommended.
     
Dedicated MacNNer
Join Date: Mar 2003
Location: UK
Status: Offline
Reply With Quote
Oct 27, 2003, 03:14 PM
 
Justification for not putting . in your path:
Imagine you navigate to a folder in which someone else has write access. They maliciously (or a virus) have placed an executable called 'ls' that does something nasty is that folder.

You go there, type 'ls', and the malicious program executes rather than just giving you a directory listing.

If you put . at the END of your path, rather than the beginning, this won't happen - but what happens if it's a common mistype, or it autocompletes... still dangerous. Anywhere in your path is still dangerous.

Just do ./a.out instead, it's safer and makes you think about what you're executing.

You might also want to put a \n in your Hello World, or it won't look right!
     
   
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 10:29 AM.
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