Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Johnny5alive

macrumors newbie
Original poster
Aug 1, 2011
10
0
Hi,

I have never done anything with any programing. I am trying to create the standard "Hello World" first program in C. Here is what happens:

1. I create the file in TextEdit and change it to plain text so I can save it as helloworld.c (have also used Text Wrangler and Xcode to create the file)

2. I open terminal and type:

gcc helloworld.c -o helloworld


3. Terminal says:

i686-apple-darwin11-llvm-gcc-4.2: try.c: No such file or directory
i686-apple-darwin11-llvm-gcc-4.2: no input files

I believe it is telling me the file does not exist? But it does. I have tried saving the .c file to multiple different locations all with the same outcome.

By changing my command to "gcc helloworld.C -o hello world" I managed to get terminal to say:

-bash: /Users/KevinsMacbookAir/Desktop/samp.c: Permission denied
(I could not repeat this outcome, which makes me think I probably
typed it wrong that time?)



I am sure I am being foolish somehow but have been trying different approaches for almost two hours. If this is as easy as it gets, programming may not be for me.

Any help is appreciated! Thanks.

EDIT: try and samp were other files I made following the same guidelines.
 
Last edited:
You're definitely typing something wrong.

I don't see try or samp in your command lines. Can you post a screenshot?

There's a thread that describes how to do this including creating the file from the command line, so I'll try to find that for you.

EDIT: Try to follow the directions in post #4 of https://forums.macrumors.com/showthread.php?p=11747938 exactly and post what happens.

B
 
Something doesn't sound right....

Assuming your code looks like this:

Code:
#include <stdio.h>

main()
{

printf("Hello World");
}

and you saved your file as something like hello.c, try this:


Open up terminal. Make sure you are on the correct path to wherever you saved your file. If its on the desktop type in something like:

cd /Users/username/Desktop (user name will be your login name and cd stands for "change directory" in case you didn't know).

Once you do that, type into terminal the command ls

ls will let you see the files in your folder that you are currently in. If you see your hello.c or whatever you named it, great.

Now type:

gcc -o HelloWorld hello.c and hit return.

gcc is your compiler, I forget what -o does (maybe someone can chime on on that flag), HelloWorld is the name of your program (you can change this to whatever you wish) and hello.c is the name of the .c file you saved.

Doing this should generate a little executable that is now on your desktop. If you click it your program should run.
 
Last edited by a moderator:
Thanks for the help! Chrono you were right, I was looking for the file in the wrong place. I couldn't get the cd/users/username/desktop command to work but the basic ls command showed me what directory it was on and my file was not there. I moved the file and it worked fine.

Balamw, the link you showed me worked as well but seemed more advanced. It cut out the whole word processor file saving step.

Thanks again!
 
Thanks for the help! Chrono you were right, I was looking for the file in the wrong place. I couldn't get the cd/users/username/desktop command to work but the basic ls command showed me what directory it was on and my file was not there. I moved the file and it worked fine.

Balamw, the link you showed me worked as well but seemed more advanced. It cut out the whole word processor file saving step.

Thanks again!

You'll definitely want to get familiar with the command line a bit. It'll be enormously beneficial and help you out a lot.

Once you get comfortable too with the basics I'd say go back to Balamw's links since they will teach you plenty more and get you heading in the right direction.

Once you do this stuff for a little bit it becomes much much easier.
 
Balamw, the link you showed me worked as well but seemed more advanced. It cut out the whole word processor file saving step.

Yeah. That's exactly the point. Everything stays together that easy to rule out problems with your editor, current working directory and filenames... The steps in that post make sure you have a working compiler.

This is something you will learn as you write more and more code. Separate variables. Take the problem apart to find your issues.

B
 
Thanks for the help! Chrono you were right, I was looking for the file in the wrong place. I couldn't get the cd/users/username/desktop command to work but the basic ls command showed me what directory it was on and my file was not there. I moved the file and it worked fine.

Balamw, the link you showed me worked as well but seemed more advanced. It cut out the whole word processor file saving step.

Thanks again!

It'd be much shorter to type:

cd ~/Desktop

Assuming of course that's where you placed the file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.