Create a C program in Windows - c

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.

Related

How to start a C project in VS 2015

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.

How to compile a program in c with a fresh copy of windows? No External Software

Is there any way to compile some Windows API code without installing any development environments to Windows?
Does Windows come with a C Compiler built in that I could just write some code in notepad, and run it through a cmd or a batch file?
.NET includes a command line compiler for C#. (not exactly what you asked for, but it might suit you.) I believe .NET is preinstalled on modern versions of Windows. Look in the folder \Windows\Microsoft.NET\Framework\v4* and see if you have a file called CSC.EXE. This is the command line compiler for C#.
See
"How can I compile a .NET project without having Visual Studio installed?"
Working with the C# 2.0 Command Line Compiler
Is it possible to install a C# compiler without Visual Studio?
For more information and examples.
You can also get the free version of Visual Studio that supports C++. Download Visual Studio Community 2013
No version of Windows I am aware of comes with a C compiler.
No, Windows does not come with a C compiler.
And I don't mean to sound patronizing, but why do you think it'd make sense for it to come with one? Sure, it'd be handy --- if it were a decent compiler --- but beside that, it is not required for normal OS operation. An optimizing compiler is a complex piece of software that would not see any use at all from most users (since most users aren't developers --- and even they might prefer using a compiler of their choice instead of something that just happened to be around).
I should note that at least some Linux distros also come without a compiler by default (as long as it's not needed as a dependency for something else --- which, granted, can happen easily).
As others have pointed out, Windows does not come with a preinstalled C compiler. There are several good free one available for download (including a freeware version of microsoft visual c), but that does not mean you can't access with Windows API/SDK.
If you need to make API/SDK calls without the requirement you install anything, you can use Windows Script Hosting https://en.wikipedia.org/wiki/Windows_Script_Host. It supports a number of languages out of the box, such as Jscript, VBScript, and has the ability to add even more options. Using Windows Script Hosting you can create any call you require into the Windows API/SDK.
Newer versions of windows have started to move towards powershell which is even more powerful -- but is not yet universally available which might mean having to install addition software (which I assume is what you are trying to avoid).
I think you may want Visual Studio Express.
http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
You do not mention which version of Windows. Also Windows API calls are customarily built with Visual C++. Although you could build with C# or VB.NET and wrap the calls. As another poster mentioned, if your version includes a .NET, then there are command line building tools available

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.

debug C for UNIX API on Windows 7 with Cygwin?

I am just learning about Cygwin, and it appears to make possible to write C code against the UNIX API, and then have it run on Windows, provided you build it in the Cygwin environment.
I have gotten accustomed to the Visual Studio IDE and debugging tools, so wanted to ask: is it somehow possible to write and build C in Windows, and then debug it with Visual Studio, with the help of Cygwin?
No, because the VS debugging tools (for the most part) depend heavily on it being compiled using the MS C compiler, rather than GCC.
So if you manage to bootload it in, you won't get any of the more useful debugging features VS offers.
The closest alternative to Visual Studio that supports GCC is Eclipse.
Visual Studio isn't an option for your case because the VS collection of tools are designed to work with code compiled using the VS C compiler and not GCC. In lieu of Visual Studio, I suggest Codelite. It's designed specifically as a cross-platform IDE that will be familiar to developers that have migrated from Visual Studio. It will of course handle GCC or Clang.
In comparison to CodeBlocks (another potential IDE you can use), Codelite has a large number of features that are slightly improved, but it does have a few that are worth mentioning individually.
Clang driven code-completion and code tagging. This is separate from the compiler, so even when compiling with GCC the IDE can provide you with Clang-based features. As a word of caution, Clang supported features are not yet entirely implemented. For instance, Clang code suggestions aren't present, and code-completion doesn't yet work for Objective-C.
Partial support for Objective-C out of the box. CodeBlocks needs to be properly setup to correctly handle Objective-C projects, while Codelite can handle them without any modifications. I say partial support for Objective-C because of the aforementioned missing code-completion for Objective-C methods and classes.
Much higher quality build error output window; catalogues all build errors and warnings by message, file and project. The only thing I can directly compare it to is the build error output window in Xcode.
My suggestion is to try both IDEs and decide on which will better suit your needs.
It is actually possible to debug UNIX apps with Visual Studio. See Utilities and SDK for Subsystem for UNIX-based Applications.

Compiling and Distributing C Programs

I just finished a semester up of C programming for a class I'm in, and it has left me with some questions that I was hoping to get answered.
During my class we have been using GCC to compile C programs. This is all good and well, but I have a question about compiling.
What if I wanted to build a C program on Windows? There is no GCC. Is that what Microsoft Visual Studio is for?
Also, what if I wanted to compile a program and distribute it? What would I compile to distribute to other Window's users?
In summary, I know how to write C programs, but I just don't get how you would make a program to give to someone who doesn't have a C compiler and is basically computer dumb.
Thanks in advance,
Ryan
Generally you will need to do two things:
Compile your program into a stand-alone executable or binary.
a. On Windows this would be a win32 executable.
b. On Linux this would be an elf binary.
Create an installer package for your program.
a. On Windows you might use NSIS, Microsoft MSI, or InstallShield.
b. On Linux you would do well to use a packager for the distribution you want to target.
Anecodtally, it is very easy to utilize Eclipse CDT and NSIS to develop C and C++ software on Windows without needing to pay any license fees.
Eclipse CDT: http://eclipse.org/cdt/
Starter Guide: http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx
NSIS: http://nsis.sourceforge.net/Main_Page
Note that if you use Visual Studio then you will also need to compile in release mode and distribute the Visual Studio CRT or .NET runtime(s). It depends upon how you link to the standard library provided by your compiler.
you can get GCC for windows....
but, Visual Studio is probably a better choice.
Once you have built it, you can use something like Wix or InnoSetup to make an install program for it.

Resources