Introduction to Programming

Creating Hello World

Example Command Line Session


Type green text exactly
Replace blue text with something else

First bring up a linux style command prompt.
On the Mac: Find Applications/Utilities/Terminal and double-click it.
On Windows: Find cygwin on your desktop and double-click it.

cd ~ Get the ~ tilde by holding down shift and hitting the ` key. It's right under the escape key. This is a shortcut to say "go to my home directory"
mkdir your_name Create a directory with your name to keep your files together.
cd your_name Go into the new directory
nano hello.c Create a new file called "hello.c". When nano comes up, type in the "Hello World" program (look here). When you're done, hit control-x to exit... and tell it that, yes, you wish to save, and the filename is really still hello.c (you'll see the prompts at the bottom).
gcc hello.c -o hello Now use the "gcc" compiler to turn your program into an executable! Just like that. If the compiler has any problems, it will let you know. If it succeeds and there are no problems, you'll just get another prompt.
./hello Now try running the executable. Note the "dot slash" in front of it. The period means "this directory." Normally you can't run commands from the current directory. The dot-slash just tells the computer, "This command is in the current directory."

If everything worked, the last command should spit out "Hello, world!" onto the screen, and you'll get another prompt. If something went wrong, you will quickly learn what the word "debugging" means! :)


Next: Hello World

Previous: Linux Style Command Line


Introduction to Programming

Home