How to write ANSI C programs by using Visual C++ .NET or Visual C++ 2005 (829488)



The information in this article applies to:

  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

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 "Hello World!" 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:
  1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual C++ Projects.

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

    The Win32 Application Wizard - FirstApplication dialog box appears.
  7. In the Win32 Application Wizard dialog box, click Application Settings in the left pane.
  8. Under Application Type, click to select any of the following options:
    • Console application: Creates a simple console application. The application files include a .cpp file that contains an empty main function.
    • Windows application: Creates a simple Microsoft Windows-based application. The application files include a ProjectName.cpp file that contains a _tWinMain function. You can use this type of application to perform graphical user interface (GUI) based programming.
    • DLL: Creates a 32-bit Windows-based DLL application project.
    • Static library: Creates a 32-bit Windows-based DLL application project.
    To create a simple "Hello World!" program, click to select Console application.
  9. Under Additional options, click to select the Empty project check box.

    Note To create a simple "Hello World!" program, do not select this check box. Instead, let the wizard generate the code for you.
  10. Click Finish.
  11. In Solution Explorer, right-click the Source Files folder, point to Add, and then click Add New Item.
  12. In Add New Item - FirstApplication dialog box, click C++ File (.cpp) under Templates.
  13. In the Name text box, type Test.c, and then click Open.
  14. In the Test.c code window, paste the following code:
    #include <stdio.h>
    
    int main()
    {
    	printf("Hello World\n");
    	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.
  15. On the Build menu, click Build Solution.
  16. Press CTRL+F5 to run the application. You receive the following message in a Command Prompt window:Hello World
    Press any key to continue

REFERENCES

For additional information about the C1010 compiler error, click the following article number to view the article in the Microsoft Knowledge Base:

815644 INFO: Most Common Causes of C1010 Error


For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MajorLast Reviewed:1/4/2006
Keywords:kbSample kbcode kbProgramming kbwizard kbhowto KB829488 kbAudDeveloper kbAudITPRO