Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: Create a Hello World app in C?

How can I create a basic C app in Visual Studio, be it 2010 Ultimate or 2008 Professional? I have searched through the project templates, and can find plenty for C++, but none for C.

(I'm hoping that the compiler and debugger will be built in.)

like image 778
Nick Heiner Avatar asked Jan 31 '10 01:01

Nick Heiner


2 Answers

New project/Win32 Console Application/Empty project.

Add a file called "hello.c" (important that it's .c)

Type out a basic hello-world:

#include <stdio.h>

int main()
{
    printf("Hello world\n");
    return 0;
}

Compile, execute... PROFIT!

like image 167
Seva Alekseyev Avatar answered Nov 11 '22 16:11

Seva Alekseyev


Visual Studio doesn't have a separate compiler for C, it uses the C++ compiler for C code. You can tell it to restrict itself to legal C syntax by using a compiler switch or by renaming the .cpp file to .c

Edit: I'm still using 2005 on this machine, so it might not be in the same place, but try this

  • Right click on the main.cpp in the solution explorer pane (on the right).
  • Choose Properties (bottom of the menu)
  • Open up the C/C++ group of properties
  • choose Advanced page
  • Change "Compile As" property to "Compile as C Code (/TC)"
like image 23
John Knoeller Avatar answered Nov 11 '22 14:11

John Knoeller