How to Program in C-simple Tutorial

6,621

21

8

Posted in TechnologySoftware

Introduction: How to Program in C-simple Tutorial

Please Comment if you like this!

This Instructable will teach anyone to write a simple program in the C programming language.

What you will need:

a Macintosh Computer with the Developer tools installed,
and some brain power.

Step 1: Write Source Code

open the program Terminal in your Utilities folder, then type pico at the prompt.

Step 2: Type Source Code

Okay, now type this into the pico editor:

#include

int main()
{
printf("Hello!\n");
}

Step 3: Save Your Program

Now, save (Ctrl+o) the file as HELLO.C

Next, quit pico(Ctrl+x).

Step 4: Compile!

Type into the prompt:

gcc HELLO.C -o Hello

Step 5: Run Your Program!

In the prompt, type:

./Hello


This should run your program. Congratulations! You have just created your first C program!

Share

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    8 Comments

    I am a C programmer. Although I wouldn't have ever learned much from this, it is nice to see something not Batch. P.S. Is it possible to tell an autorun.inf file to run a C program?

    Yes, but I believe that is only an editor. You would need to find a compiler too, such as the open source GCC compiler, try http://www.mingw.org/ or just google "gcc for windows".

    that's not realy a c tutorial, it's more like how to write a c program

    I think that these days I'm inclined to recommend something like Processing to people who want to learn C. This is an "environment" with C underneath, but with major features implemented as a sort of "subset" so that you don't have to worry about quite as much. Also, it includes libraries of functions aimed at allowing relatively non-technical people to do fancy things (graphics...) (In the "microcontroller" space, Wiring and Arduino do the same thing (and in fact are based on the same core environment, I believe.))

    Let me tell you something -- I like it. Cool for a first instructable too. :-)

    It would have been nice if you had included some information explaining what each part of the code does. Such as '#include' being used to include an external header file. 'int main' is the body of the program etc I can't confess to knowing much C, which is why even the most basic of knowledge would be of use. Well done on your first Instructable through, nice to see something other than Batch :]