How to start a C project in VS 2015 - c

I have Visual Studio 2015, and I was wondering if it supports C.
I press on "New Project" and the options are
Visual C#, Visual C++, Visual Basic.
I was wondering if I could compile a C programm or do one in VS.
Does it have a C compiler ?
I am lost.
Thanks in Advance.

Create a visual c++ project.
Just rename your source file from .cpp to .c
No special conversions required. Just type your valid c code and it will compile just fine.

You can either do as Douglas DeTellem has suggested (Simply start a C++ project, change the extension to ".c", and just use their C++ compiler (C++, is of course, a superset of C), or you can try downloading MinGW (http://www.mingw.org/) and installing the Windows version of gcc, which supports the old C standard.
If you really want an IDE, try looking at Codeblocks (http://www.codeblocks.org). If you pick the download with MinGW, it will include the C compiler, and help you.
I tend to prefer using a text editor (in my case, gVim) and using a command prompt to run gcc, or cl (the Visual Studio command line call to the compiler and linker) to compile my programs.

Related

Visual Studio Code does not include C header files

I recently downloaded Visual Studio Code to begin learning the C programming language. I installed the program as well as the C extension. However, when I tried to create the "Hello, World!" program, it would not run, and in the Problems menu it did not recognize the stdio.h header file, saying that I need to update my includePath. I have not been able to find any stdio.h file on my computer to link to. Do I need to download the C library files (even though I have read they should be included with the compiler), and if so, where can I find them? Or is there another solution? Thanks, and sorry if this is a stupid question, I am new to this.
I think you might be confusing VS Code with the VS IDE.
VS Code is a source editor only; that is to say that it's basically just a glorified text editor. It has the ability to load extensions and open a shell to compile the code, and there are a few extensions that let you debug the code itself, but they can be tricky to get setup and installed to work well with C/C++ code. VS Code does not have a compiler/assembler/linker nor the requisite headers or SDK's as that is up to you (the user) to install and then point to those in your settings file.
The Visual Studio IDE, on the other hand, is a complete integrated development environment that also includes the system headers and SDK's for Windows, as well as the binaries to properly compile, link and assemble your code into a binary for a Windows system (cross platform is possible as well). The Visual Studio IDE comes in many different flavors with the latest being VS 2017.
If you wish to stick with VS Code, you'll need to grab a compiler and the appropriate header files for the system you're targeting. If you wish to just stick with Windows for now, you can grab the Windows 7 SDK here or the Windows 10 SDK here .. you could even grab both and just reference the one you wish when you want. Note that the Windows 7 SDK includes the Microsoft C/C++ compiler, alternatively you can download the MSVC compiler from their Build Tools site.
There's also Cygwin in which you can use the GNU compiler, and of course Clang, which can be referenced in both VS Code and the VS IDE.
I hope that can help.

C programming in Visual Studio

Can I use Visual Studio to learn C programming? In the new project menu I can choose between Visual Basic, Visual C#, Visual C++, Visual F# and others but I don't see "C" or "Visual C".
Short answer: Yes, you need to rename .cpp files to c, so you can write C:
https://msdn.microsoft.com/en-us/library/bb384838.aspx?f=255&MSPPError=-2147217396
From the link above:
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.
That being said, I do not recommend learning C language in Visual Studio, why VS? It does have lots of features you are not going to use while learning C
Yes, you very well can learn C using Visual Studio.
Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the .c file extension to save your source code.
You don't have to be using the IDE to compile C. You can write the source in Notepad, and compile it in command line using Developer Command Prompt which comes with Visual Studio.
Open the Developer Command Prompt, enter the directory you are working in, use the cl command to compile your C code.
For example, cl helloworld.c compiles a file named helloworld.c.
Refer this for more information: Walkthrough: Compiling a C Program on the Command Line
Hope this helps
Yes it is, none of the Visual Stdio editions have C mentioned, but it is included with the C++ compiler (you therefore need to look under C++). The main difference between using C and C++ is the naming system (i.e. using .c and not .cpp).
You do have to be careful not to create a C++ project and rename it to C though, that does not work.
Coding C from the command line:
Much like you can use gcc on Linux (or if you have MinGW installed) Visual Studio has a command to be used from command prompt (it must be the Visual Studio Developer Command Prompt though). As mentioned in the other answer you can use cl to compile your c file (make sure it is named .c)
Example:
cl myfile.c
Or to check all the accepted commands:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27030.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>
Coding C from the IDE:
Without doubt one of the best features of Visual Studio is the convenient IDE.
Although it takes more configuring, you get bonuses such as basic debugging before compiling (for example if you forget a ;)
To create a C project do the following:
Start a new project, go under C++ and select Empty Project, enter the Name of your project and the Location you want it to install to, then click Ok. Now wait for the project to be created.
Next under Solutions Explorer right click Source Files, select Add then New Item. You should see something like this:
Rename Source.cpp to include a .c extension (Source.c for example). Select the location you want to keep it in, I would recommend always keeping it within the project folder itself (in this case C:\Users\Simon\Desktop\Learn\My First C Code)
It should open up the .c file, ready to be modified. Visual Studio can now be used as normal, happy coding!
Yes, you can:
You can create a C-language project by using C++ project templates. In the generated project, locate files that have a .cpp file name extension and change it to .c. Then, on the Project Properties page for the project (not for the solution), expand Configuration Properties, C/C++ and select Advanced. Change the Compile As setting to Compile as C Code (/TC).
https://learn.microsoft.com/en-us/cpp/ide/visual-cpp-project-types?view=vs-2017
You can use Visual Studio for C, but if you are serious about learning the newest C available, I recommend using something like Code::Blocks with MinGW-TDM version, which you can get a 32 bit version of. I use version 5.1 which supports the newest C and C++. Another benefit is that it is a better platform for creating software that can be easily ported to other platforms. If you were, for example, to code in C, using the SDL library, you could create software that could be recompiled with little to no changes to the code, on Linux, Apple and many mobile devices. The way Microsoft has been going these days, I think this is definitely the better route to take.
Download visual studio c++ express version 2006,2010 etc.
then goto create new project and create c++ project select cmd project check empty rename cc with c extension file name

How to compile and execute C program on Visual Studio 2012 for Windows 8?

I was looking for a C compiler for Windows 8 and then came to know that I can compile C programs on Visual Studio.
Microsoft offers a walkthrough for the same, but I don't like it since it includes writing program in text editor and use of command prompt frequently, I am looking for more like a Turbo C++ interface.
Is there anyway I can run and compile programs directly in Visual Studio 2012 for windows 8 itself?
Or if that's not possible, what alternatives I have for windows 8?
From the page you posted:
By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code.
Now create any C++ project type you want and when you add the files, ensure they end in .c and you are done.
Since you asked for alternatives (not clear if you meant even alternative IDEs and/or compilers):
You could try the free Code::Blocks IDE which has support for MINGW, which includes a port of GCC (Gnu Compiler Collections) for Windows. An alternative, and sometimes easier to install, port of GCC based on MINGW is TDM-GCC. Code::Blocks can also be configured to work with other toolchains.
An advantage of using GCC is that it is the default compiler for Linux systems, so if you will happen to code for Linux too, you could "reuse" your knowledge of the GCC compiler you used on Windows.
Another alternative IDE could be eclipse, with its CDT extension, aimed at C/C++ development (can be configured to work with GCC or with many other toolchains). Much heavier than Code::Blocks, but with much more features.
you can use visual studio as TURBO C++
But here
if you want to compile single file
create program.c
file->new->c++file->open
then write c code and save it with extension .c
Now you need to create new project
and file->new->project
add program.c to this project.
and compile the project By using build->compile. before that change compile as with the
project->properties.
The last time I used Turbo C++ (in the early 90s), it was an IDE just like Visual Studio.
Both Turbo C++ and Visual Studio offer command line tools.
From the start menu, find the Visual Studio tools menu, there should be a command line shortcut there that allows you access to the command line (cl.exe) tools.
If you have makefiles, then you can use nmake rather than make.

POSIX-compatible regex library for Visual Studio C

I'm working on a C program which will be run in Linux and from inside Visual Studio 2010, and I'm looking for a regex library. GNU comes with a POSIX-compatible regex library, but Visual Studio, despite having C++ std::regex, doesn't have a C-compatible library. GNU has a Windows version of their library (http://gnuwin32.sourceforge.net/packages/regex.htm), but the DLLs are 32-bit only and the source code can't compile in Visual Studio (~500 errors!). My only requirement is that the end-user should not have to install anything extra, and should get the same behaviour on both platforms. I'm not picky about whether it's POSIX-style, Perl-style or something else. What should I do?
Thanks in advance.
The one library I've found that compiles with basically no effort, and is also the smallest, is: https://code.google.com/p/slre/. It's pretty basic but is good enough for my purposes. Thanks for the help, though.

Create a C program in Windows

I want to create a small C program and I would like to use the Windows command prompt to compile and run it. Can anyone suggest to me how to install a C compiler that works with the command prompt and the way to use it? How do I install the compiler, compile the code and run the program?
Download Visual Studio Express 2010 C++. From the File menu, choose New, then Project. Under Project Types, expand the tree view to Visual C++ -> General, then choose the template for Empty Project. Give it a name and a location. Click OK. Type in some C code, then Build and Run it.
It's a fairly simple tool to use, so I'd recommend you just go ahead and try it out.
There's several compilers available for Windows. Two popular ones are Microsoft Visual C++ and MinGW.
Using Visual C++, you can compile a program like so:
cl /Femyprog.exe myprog.c
Using MinGW, you can compile a program like so:
gcc -o myprog.exe myprog.c
Most programmers don't use command prompts to compile very much any longer. We use IDE's instead, because they're a hell-of-a-lot more convenient. Having said that there's no reason why you can't use the command prompt to "manually" execute the compiler which underlies, say, Microsoft Visual Studio.
So... If I where you I'd start by downloading Visual Studio 2010 C++ Express Edition from Uncle Bills Funny Farm. Note that C++ IDE (and compiler, or course) supports the old ANSI-C language as well as C++... in fact C++ is a "superset" of ANSI-C.
Your other options are a bit limited on Windows. I believe that GCC: GNU's C++ Compiler works on Windows... but it's "got a few issues" which nobody is any particular hurry to fix, simply because by far the majority of the GNU boys are running Linux, and they sort-of look down on Windows as "an interesting experiment [which failed]".
Cheers. Keith.

Resources