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

18 downloads 98 Views 13KB Size Report
An example program to compile and run using the Visual C++ compiler: ... Compiling and running a C program with this compiler requires several steps. a) From ...
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. */

n = 50; /* The loop itself */ for (i = 0; i "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: http://commandwindows.com/). e) In the command window, type "cl counter.c". The command "cl" starts the C compiler with the

2

file "counter.c" as its input. This will compile your C program into a form that can be executed by the processor. 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!

Suggest Documents