Can I use Microsoft Visual Studio For coding C ?

  • C/++/#
  • Thread starter Arman777
  • Start date
  • #1
1,911
149
I will take Intro to C programming this semester and can I use MVS for coding C ?
 

Answers and Replies

  • #2
34,687
6,393
I will take Intro to C programming this semester and can I use MVS for coding C ?
Yes. I use it for both C and C++ programs.

A C program should have a name with a file extension of .c. The extension for C++ programs is .cpp. There are also some switches in the property pages for your code to specify which language, but the easiest way is to use the file extensions I listed.
 
  • Like
Likes harborsparrow and Arman777
  • #3
1,911
149
Is it possible that it can harm my computer If I do smthing wrong in the downloading process ? How can I download and run it safely ?
 
  • #4
34,687
6,393
Is it possible that it can harm my computer If I do smthing wrong in the downloading process ? How can I download and run it safely ?
I haven't heard of anyone having something go wrong when they downloaded Vis. Studio.
 
  • Like
Likes Arman777
  • #5
1,911
149
I haven't heard of anyone having something go wrong when they downloaded Vis. Studio.
İnstructor shared a link for to run C in MinGW. But I couldnt download it from there cause its too complex .
http://mingw.org/wiki/Getting_Started
"After installation you will need to perform some additional tasks yourself to ensure your MinGW applications will run. Most importantly, you will need to make changes to your PATH environment variable. Be careful: there are two PATH variables which can be changed, and changing the wrong one can have significant consequences. Instructions for changing the correct PATH variable are provided below."

And many more warnings etc. I guess theres no such needs in MVS
 
  • #6
jim mcnamara
Mentor
4,230
2,799
Simply download cygwin. It is a windows app. It acts like linux. Free. https://www.cygwin.com/

If you cannot do that and you are on Windows 10, then you can get an Ubuntu Linux app. Free. Install WSL from Microsoft.

In either case you need to understand that Windows text files have a line ending (carriage control) of ASCII 10, and ASCII 13. Two characters usually noted by "\n" and "\r". (\r shows in UNIX editors as "^M" which is a red flag.)

Ubuntu and cygwin use ONLY "\n". In Linux speak, this is called a UNIX file, the other one, "\n\r", is called a windows file. Most editors will change a text file to either one. If you use a windows editor, then compile it in Linux you will get a bunch of errors because of the wrong line ending. So fix the type of file first. Then, no errors.
 
  • #7
verty
Homework Helper
2,164
198
If you do use GCC, consider using the editor SciTE. If you turn on line numbering it'll make debugging very easy because GCC has very good error messages when you use -Wall -Wextra -pedantic. I suppose the one challenge with GCC is you need to learn how to write a Makefile but that is not hard to do and once you have the file, you can always reuse it. (A Makefile is like the solution in Visual Studio. It references all the files of your project and compiles it in the correct order to produce the executable.)
 
  • #8
1,911
149
I need some good explaining videos for these possible C IDE s.
 
  • #9
QuantumQuest
Science Advisor
Insights Author
Gold Member
926
485
I will take Intro to C programming this semester and can I use MVS for coding C ?
I agree with @Mark44 that you can download and use it with no problems. It is a good super-IDE but just try to stay focused on your code and learn the extra IDE features with patience. Many years before I was using DevC++ and it was good enough for educational purposes as well as for building some open source software.- more recently I had installed a fork with C++11 support. There is a relatively new release at SourceForge.net .

İnstructor shared a link for to run C in MinGW. But I couldnt download it from there cause its too complex .
http://mingw.org/wiki/Getting_Started
"After installation you will need to perform some additional tasks yourself to ensure your MinGW applications will run. Most importantly, you will need to make changes to your PATH environment variable. Be careful: there are two PATH variables which can be changed, and changing the wrong one can have significant consequences. Instructions for changing the correct PATH variable are provided below."

And many more warnings etc. I guess theres no such needs in MVS
I always liked to tinker with tool chains particularly of GCC, as a way to learn and set up things exactly the way I like. The same holds for maintaining and modifying if necessary the PATHs of Windows, as for a lot of other Windows OS things. But these don't come as suggestions without warnings. If you really like to do it this way - even independently of Microsoft Visual Studio, you have to study through resources, references and tutorials and do things in a safe way without putting anything at stake. If you're aiming to be a good programmer or software developer, I would also recommend to learn to program on a Linux distro besides Windows.
 
  • #10
1,911
149
I did a bit research and find that Code Block is best for beginners. I downloaded it and I can manage to use it

I downloaded the MVS and tried to use it but some problems came up which I dont remember now. But maybe I download it later. But for now I think Code Block is nice and have much simpler user interface for me.
 
  • Like
Likes symbolipoint
  • #11
verty
Homework Helper
2,164
198
I installed VC++ because I wanted to see how easy it was to set up but I can't get it to work right either. For example, I tried to #include <stdio.h>; and it complains, but #include <cstdio>; doesn't.

@Mark44, can you elaborate on what settings need to change to enable C in the most compatible way possible? Thanks.
 
  • #12
QuantumQuest
Science Advisor
Insights Author
Gold Member
926
485
I installed VC++ because I wanted to see how easy it was to set up but I can't get it to work right either. For example, I tried to #include <stdio.h>; and it complains, but #include <cstdio>; doesn't.
Assuming that you have installed the Visual C++ redistributable for Visual Studio 2017, you can create "New Project" > "Visual C++" > "Win32 Console Application" >"Next" > "Console Application" and "Empty Project". Now, click "Finish" and add a new source file from the relevant menu and give your source file name the .c extension, ignoring the options displayed. Hope this helps.

As for <cstdio>, it includes <stdio.h> and adds the associated names to the std namespace. Here's the relevant Microsoft web page.
 
  • #13
verty
Homework Helper
2,164
198
Assuming that you have installed the Visual C++ redistributable for Visual Studio 2017, you can create "New Project" > "Visual C++" > "Win32 Console Application" >"Next" > "Console Application" and "Empty Project". Now, click "Finish" and add a new source file from the relevant menu and give your source file name the .c extension, ignoring the options displayed. Hope this helps.

As for <cstdio>, it includes <stdio.h> and adds the associated names to the std namespace. Here's the relevant Microsoft web page.
Thanks. It was my fault in the end, I deselected a bunch of stuff in the installer, too many in fact, but adding them back left the solution in a confused state. I had to delete it and create a new solution and it's now working properly. I think I prefer Code::Blocks (I tried that after Arman mentioned it) because it's closer to how it is on Linux. The one difference I see is it uses g++ to link the executable like so: g++ -o myapp.exe main.o. But otherwise it's just like it is on Linux which should be very compatible with his class although from what I can tell, adding main.c to an empty project in MSVC is working fine as well.

@Mark44, there's no need to reply because I've got it working. It was my own fault in the end for trying to make the install smaller.
 
  • #14
34,687
6,393
@Mark44, can you elaborate on what settings need to change to enable C in the most compatible way possible? Thanks.
Once you have loaded your project in VS, open Solution Explorer, if you don't already have that as a pane that is showing. To open the Solution Explorer pane, under View, click Solution Explorer.

Select the source code file in your project (I'm assuming you have only one source code file). From the right-click menu for that file, choose Properties, the last selection in this list. This opens a dialog box labelled <File name> Property Pages.

In the left pane at the top level it says Configuration Properties. Under that there are two headings: General and C/C++. Expand the C/C++ heading. Two up from the bottom is Advanced. One option there is Compile As, which normally has Default as the option. Change this option to Compile as C Code, if that's how you want your code to be compiled. After that, click OK if you're done, or Apply if you want to change some other settings and aren't ready to close the Property Pages.

As I understand things, the usual setting of Default causes source files whose extension is .c to be compiled as C code, and files with a .cpp extension are compiled as C++ code. If you manually change the Compile As setting as described above, you can choose which back end does the compilation regardless of the file extension you have used -- I believe.
 
  • Like
Likes verty and jim mcnamara
  • #15
phinds
Science Advisor
Insights Author
Gold Member
16,732
7,413
I will take Intro to C programming this semester and can I use MVS for coding C ?
Just FYI, C coding is what MVS started with and it has never been left out. As for installations, I've installed many versions on several different machines and have never had the least bit of problem. It's really wonderful that MS now gives away the full version to individuals. I've paid out quite a bit for versions over the years (I've been using it from the beginning) and I was delighted when I found that it's now free.
 
  • Like
Likes aaroman, QuantumQuest and jim mcnamara
  • #16
rcgldr
Homework Helper
8,728
545
I use Visual Studio desktop express 2015, which is the last version before Microsoft switched to the community version. You can start here to download an "older" version:

https://visualstudio.microsoft.com/vs/older-downloads

Either way, you'll need to create a Microsoft account. If you're running Windows XP or XP X64, then the latest version of VS that will run on XP is Visual Studio C/C++ express 2010 (instead of desktop express). VS2010 is available as an ISO file. I don't think you need a Microsoft account to use VS2010.

Note that Microsoft's C compilers are essentially C89 compliant, not C99 or later. I'm not sure of the differences. Some C compilers allow variable length arrays (VLA), but even C++ standards don't support VLA, so I would avoid it. If you want a stack based array, you can use _alloca() with VS (it may be called alloca() for other compilers), but be aware if that if a stack based array is too large, you can get a stack overflow error.
 
  • #17
verty
Homework Helper
2,164
198
Thinking of C again reminds me of when I learned to program using Turbo C++. The help pages were very good and I've liked C languages ever since. I particularly like how everything is pretty easy to do if you know what function to call. Functions like memset, memcopy, etc, don't seem to exist in other languages. And I like how pointers work like arrays. And you can pass by reference by using the address-of operator (&). And of course it has the switch statement that has made it into almost every language but not Python for some reason. So I do like C and this was a nice reminder, seeing if MSVC could work in a compatible way. So thanks.
 
  • #18
harborsparrow
Gold Member
610
154
Visual Studio is very good and stable. It installs easily. I would suggest you go with it if you are willing to learn to use it. You might need to get a book (used on Amazon, where you can see reviews of the books) to get familiar with its interface. I've used a bunch of those cygwin and other tools and much prefer Visual Studio.
 

Related Threads on Can I use Microsoft Visual Studio For coding C ?

Replies
10
Views
2K
  • Last Post
Replies
7
Views
25K
Replies
10
Views
5K
Replies
25
Views
13K
Replies
7
Views
2K
Replies
16
Views
489
Replies
6
Views
9K
Replies
1
Views
4K
Replies
6
Views
5K
  • Last Post
Replies
6
Views
3K
Top