简体   繁体   中英

My C code is not running in Microsoft VS CODE

#include <stdio.h>

int main()
{
    int a,b;
    printf("Enter the value of a\n");
    scanf("%d",&a);
    printf("Enter the value of b\n");
    scanf("%d",&b);
    printf("The sum of a and b is %d", a + b);
    return 0;
}

When i run this code in Microsoft Visual Code the code doesn't stop executing nor do i get the output. It starts running but it does not stop. I am also not getting any output. Other type of code is working perfectly fine. Anyone can help me with this? click here for image from vscode showing the running window

if this thing happens again first again try to execute the same code with some other IDE or run your code separately with CMD or PowerShell.

The code you have written is 100% correct. Take care of the following things, check it out, if you have done them:

  1. Install gcc in your system. gcc helps u compile c or c++ codes.
  2. Install a C/C++ extension from the extensions section in the visual studio code.
  3. At last, if the situation is still the same, try to re-install the visual studio code.

I hope, this might helps you. If you liked my suggestion, please press the upvoke button to motivate me to write such answers for you.

Thanks!

Code runner extension runs code in the output file which can not be interacted with. You have to change it so it runs in the terminal. Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration. Find and check the box Run in Terminal.

I had exact same problem and it turns out I forgot to save the code:)

The main reason why code is not running is because it is running in "Output" Window, which I had shown in the linked Image. If you want to run code properly then you have to run it in "Terminal" Window.

For running your code in "Terminal" window you have to follow these steps: Step 1: Open Settings. Step 2: Then type "Run in Terminal" in search box of the setting. Scroll below and find that setting. Install code runner if you haven't. Step 3: Tick the box which is in 2nd line.

After that your code will run properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM