How to Program in C-simple Tutorial

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!

Be the First to Share

    Recommendations

    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    8 Discussions

    0
    tinkerC
    tinkerC

    11 years ago on Introduction

    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?

    0
    musicman432
    musicman432

    Reply 11 years ago on Introduction

    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".

    0
    DeriemD
    DeriemD

    12 years ago on Introduction

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

    0
    westfw
    westfw

    12 years ago on Introduction

    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.))

    0
    GorillazMiko
    GorillazMiko

    12 years ago on Introduction

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

    0
    PocketSized
    PocketSized

    12 years ago on Introduction

    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 :]