You are hereStarting Programming

Starting Programming


Starting programming is easy.

On Linux..

If you are using Linux, just fire up a Teriminal and use GCC:

gconway@gconway:~$ gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

On the off chance that you don't see the above output, you may need to install GCC. Just use your package manager to grab it.

On Mac OS X..

If you are on a Mac, just download the Xcode package from Apple Developer Connection (you'll need an Apple Login for this):

https://developer.apple.com/devcenter/mac/

Then fire up a Terminal just like on Linux and start using GCC like above.

On Windows..

If you are using Windows (XP/Vista/Win7), you need to download  a C/C++ compiler. We recommend the MinGW compiler package.

MinGW provides a complete Open Source programming tool set which includes a port of the GNU Compiler Collection (GCC) C/C++ compilers and other language compilers; See the MinGW Getting Started page for instructions on how to install it:

http://www.mingw.org/wiki/Getting_Started

In Brief...

  • Download the MinGW Graphical User Interface Installer: mingw-get-inst
  • Follow the defaults - install into C:\MinGW
    • NOTE: MinGW does not like directories name with spaces!!
  • Add it's 'bin' directory to your PATH:
    • start > run > cmd
    • set %path%;C:\MinGW\bin
    • you need to do this each time you start a command-prompt. Or put C:\MinGW\bin into the System path
    • mkdir C:\MinGW\MyCPrograms
      • Keep your C programs in here... note.. no spaces in the name!

My First C Program

start up your favourite editor.. just use notepad in Windows for example:

  • notepad myfirstCprogram.c
  • Put the following code into your C file:
#include <stdio.h>

int main(void) {

    printf("Hello World\n");

    return 0;
}

This program just prints out "Hello World" to the screen. The first line tells it to use the standard input/output library (stdio.h). The "main" function is then described. This contains the command to print to the screen and then return a value of zero to the operating system, indicating that it finished normally, with no problems.

If you get an "error" then you cannot run your program and you must fix the error. It's usually just a syntex error - remember it's case sensitive!

  • Save this code as myfirstCprogram.c in your C:\MinGW\MyCPrograms folder
  • You can then compile your source code.

    • gcc -o myfirstCprogram myfirstCprogram.c
  • Then run it!
    • myfirstCprogram

If that worked for you, congratulations! You've just created your first C program!

Tutorials

There are many C/C++ tutorials on the internet. Here are a few..