Tuesday, January 15, 2008

Compile C Programs in Visual Studio 2005

Lately, I've been gearing towards OO programming than structure programming such as C.  Just a few weeks ago, I wanted to write a C program and I totally forgot where to start because I no longer have my Linux box with me.  On my Windows box, I have Visual Studio for C# and Eclipse for Java.  After googling around the web for about ten minutes, there is a possible way to develop C programs in Visual Studio.  Below are the steps.

File -> Programs -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio Command Prompt 2005

At the command prompt, call notepad to create a new C file.  The command for this is "notepad test3.c"

image

Write your code, for testing purposes, I wrote a "Hello World" program

image

Now compile your code by going back to Visual Studio 2005 Command Prompt and type in "cl test4.c"

image

Finally, execute your C program by calling the name of your program.  For example, mine would be "test4" and the result gets displayed is "Hello World"

image