question

kjslaaam avatar image
0 Votes"
kjslaaam asked JeanineZhang-MSFT commented

How to build and run .c source file opened using Visual Studio?

I am learning to program in C. I used to use Codeblocks earlier to write codes in C. Now I am deciding to switch to Visual Studio, because of its wide variety of supported languages, especially C# and VB.NET. But I cannot find any Build and Run or equivalent feature in Visual Studio after opening a .c file. Instead, there is an "Attachment" option. However, if I write a program for the first time, I can run it by clicking on "Local Windows Debugger".

c++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In VS, your source file needs to be part of a "project". The easiest way to start is by creating a new C++ console project - use File, New, Project and pick the C++ Console App.

1 Vote 1 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited

See : How to: Create a C++ Project from Existing Code
(Console application project)



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

rupeshshukla-4529 avatar image
0 Votes"
rupeshshukla-4529 answered rupeshshukla-4529 edited

Open the solution and Click on Build menu from title bar and you can see Build Solution and Rebuild Solution are there and If you look in Debug option then you can see Start Debugging and Start without Debugging . Those are the options you are looking for. You can also use shortcut , but I think that is not what you are looking for right now.

Thanks



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered JeanineZhang-MSFT commented

Hi,

As far as I'm concerned, you couldn't build and run .c source file in visual studio. Visual Studio does not support this. A project is always required, even if it only contains a single source code (.c) file. You could only run the .sln file (Visual Studio Solution) not a .c file in visual studio.

You could run a single source file through Microsoft's C++ compiler on the command line (cl.exe), and then execute it. But this doesn't involve anything about the Visual Studio IDE.

If you want to learn about how to create a standard C++ program (C++) in visual studio, I suggest you could start with the Doc: Walkthrough: Creating a Standard C++ Program (C++)

Best Regards,

Jeanine


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@kjslaaam

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·