1

I tried a very simple code of C language using scanf, and it falls into the infinite loop(or it looks like). the code is the following:

#include <stdio.h>

int main(){
    int input = 0;
    scanf("%d", &input);
    return 0;
}

I used the code runner extension. Here is the screenshot just in case. enter image description here

Does anyone know how to fix it?

starball
  • 20,030
  • 7
  • 43
  • 238
Sunwoo Jeong
  • 87
  • 2
  • 7

3 Answers3

5

I just came across the same problem. In my case, just search "code-runner.run" in the setting and check the box as follow.

Code-runner: Run In Terminal
[] whether to run code in integrated terminal.

Image instruction: screenshot

Rex Wang
  • 51
  • 1
  • 4
  • Welcome to Stackoverflow. Kindly frame the answer in a way its understandable to the other users. You can add images in a stackoverflow answer. – Aditya Patnaik Jan 08 '22 at 14:25
0

You can add some code to make a better appearance for users, for example:

#include <stdio.h>

int main(){
    int input = 0;
    printf("Please type in something:");
    scanf("%d", &input);
    return 0;
}

In this case you can know that the code is working and it gives you some feedback. Then you can type in the value which will be taken as input before the main function returns.

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
0

I had this same problem when I installed Mingw-64 and VS Code. I installed Ming from Sourceforge. When I went back and reviewed the directions for VSC, I noticed they recommended I download from MSYS2. So I removed the original installation and re-installed from MSYS2. All my problems with scanf went away. So my advice is to follow the installation instructions from the VSC website. https://code.visualstudio.com/docs/cpp/config-mingw