Creating a C File


You will often see C and C++ being used interchangably, as in the creation of projects in Visual Studio. This is because C++ is simply C with additional organizational features (known as object-oriented features). These additional features can make compilation, slower however (and some things work slightly differently in C++), and I will show you how to compile code strictly as C later on in this web page.

Creating a C File In Visual Studio 2017


To create a C project in Visual Studio for Windows, go to File-> New->Project-> Visual C++-> Windows Desktop-> Windows Console Application


To create a C project in Visual Studio for Linux, go to File-> New->Project-> Visual C++-> Crossplatform-> Linux-> Console Application (Linux)

Both Operating Systems

Then give your project a name in the "Name:" box below the project-type selection-screen. Don't include a file extension in the name, because the project name is only the name of the folder containing the C file. Also, don't put spaces in between the words in your project name. By convention, you should capitalize the first letter of each word in the project name. Keep the "Create directory for solution" option checked and click "OK".


If this is the first time you are creating a Linux project in Visual Studio, you should see a window called "Getting Started" open within the IDE. Follow that window's instructions to enable testing your applications on a Linux machine. If for some reason you don't have a Window explaining how to enable remote development in Visual Studio, you can find Visual Studio's official web site for getting started with Linux here: Visual C++ for Linux Development

Both Operating Systems

You should now have a file called main.cpp listed in a window called "Solution Explorer" to the left of Visual Studio's window. If you don't see this window, go to View (in the tool bar at the top of Visual Studio's window)-> Solution Explorer. Rename the main.cpp file (you can do this by right clicking the file in the solution explorer so you don't have to go to Window's file explorer) to main.c. However, this alone doesn't make Visual Studio compile code as C instead of C++. You mut now go to Project (also located on the tool bar at the top of Visual Studio's window)-> ProjectName (the name of your project) Properties. A window should pop up. Make sure "Configuration:" is set to "All Configurations" and "Platform:" is set to "All Platforms". Then go to C/C++-> Advanced and set "Compile As" (which should appear to the right of the window) to "Compile as C Code (-x c)". Now you are ready to code!