An example program to compile and run using the Visual C compiler Here is a very simple counter program include main int int i n The index counter The count limit by qpeoru8364


									An example program to compile and run using the Visual C++ compiler:

/* Here is a very simple counter program. */

#include <stdio.h>

    int   i;    /* The index counter. */
    int   n;     /* The count limit. */

     n = 50;

     /* The loop itself */
     for (i = 0; i <= n; i++)
           printf("The count is: %d\n",i);

In this course, we will be using the Microsoft Visual C++ compiler from a command line window.
This is not the most elegant user interface, but it provides everything we need to write and execute
very complex C programs. After all, our focus is on learning C, not writing graphical user interfaces.
This compiler is free and you can easily download it and install it on your own computer. Here is the
web site:

Compiling and running a C program with this compiler requires several steps.

a) From the Windows desktop, go to the Windows "start" button in the lower left corner and follow
this path: "start" -> "All programs" -> "Microsoft Visual C++ ..." -> "Visual Studio Tools" -> "Visual
Studio 2008 Command Prompt". A command window should pop up.

b) Type "notepad counter.c" in the command window. This will ask you if you want to create a new
file. Answer "yes." This will create a new text file that you can now edit using the simple notepad
editor. The suffix ".c" on the file tells the compiler that this is the source code of a C program.

c) Copy the above program into notepad and save it from the "File" pulldown menu.

d) If you go to the command window and type "dir" you will see a listing of all of the files in that
directory. One of them should be "counter.c". (If you are interested in what else you can do from the
command window, take a look at this web site:

e) In the command window, type "cl counter.c". The command "cl" starts the C compiler with the

file "counter.c" as its input. This will compile your C program into a form that can be executed by the

f) Now type the name of the program you have just created, "counter". You should see
"The count is: 0"
"The count is: 1"
and so on get printed in the window.

You have now just successfully entered, compiled, and executed your first C program. Nice work!

To top