Microsoft KB Archive/829488

= How to write ANSI C programs by using Visual C++ .NET or Visual C++ 2005 =

Article ID: 829488

Article Last Modified on 4/19/2007

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



SUMMARY
Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.

This step-by-step article describes how to write American National Standards Institute (ANSI) C programs by using Microsoft Visual Studio .NET. This article discusses how to write a simple &quot;Hello World!&quot; C program by using Visual C++ application wizards in the Visual Studio .NET or Visual Studio 2005 IDE.



MORE INFORMATION
The best way to create new projects is by using the Visual C++ application wizards. Visual C++ application wizards work with the application frameworks and libraries to create starter programs for you.

To create ANSI C programs by using the Visual C++ application wizards in the Visual Studio .NET or Visual Studio 2005 IDE, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. Under Project Types, click Visual C++ Projects.

Note In Visual Studio 2005, click Visual C++ under Project Types. Under Templates, click Win32 Project. In the Name text box, type FirstApplication . In the Location text box, type C:\Test, and then click OK.

The Win32 Application Wizard - FirstApplication dialog box appears. In the Win32 Application Wizard dialog box, click Application Settings in the left pane.</li> Under Application Type, click to select any of the following options: <ul> Console application: Creates a simple console application. The application files include a .cpp file that contains an empty main function.</li> Windows application: Creates a simple Microsoft Windows-based application. The application files include a .cpp file that contains a _tWinMain function. You can use this type of application to perform graphical user interface (GUI) based programming.</li> DLL: Creates a 32-bit Windows-based DLL application project.</li> Static library: Creates a 32-bit Windows-based DLL application project.</li></ul>

To create a simple &quot;Hello World!&quot; program, click to select Console application.</li> Under Additional options, click to select the Empty project check box.

Note To create a simple &quot;Hello World!&quot; program, do not select this check box. Instead, let the wizard generate the code for you.</li> Click Finish.</li> In Solution Explorer, right-click the Source Files folder, point to Add, and then click Add New Item.</li> In Add New Item - FirstApplication dialog box, click C++ File (.cpp) under Templates.</li> In the Name text box, type Test.c, and then click Open.</li>  In the Test.c code window, paste the following code:
 * 1) include <stdio.h>

int main {   printf(&quot;Hello World\n&quot;); return 0; } #include is a preprocessor directive that tells the compiler to put code from the stdio.h header file into your program. If you include header files, you can gain access to standard library functions. For example, your application must have access to the stdio.h header file to use the printf function. </li> On the Build menu, click Build Solution.</li> Press CTRL+F5 to run the application. You receive the following message in a Command Prompt window:

Hello World

Press any key to continue

</li></ol>

<div class="references_section">