How to Fix scanf() Not Working in VS Code (Run Code Runner in Terminal)

How to set Code Runner to run in terminal in VS Code to fix scanf not working

Why Is scanf() Not Working in VS Code? When using the Code Runner extension in VS Code, many beginners face this common problem: Your program runs, but it skips the input or crashes when it reaches scanf() or cin. That’s because Code Runner runs your code in the “OUTPUT” tab, which doesn’t support keyboard input. To fix this, we must make Code Runner use the terminal, which allows interactive input. How to Make Code Runner Use the Terminal Here’s a simple step-by-step guide to fix this issue in Visual Studio Code. Step 1: Open VS Code Settings (JSON) Press Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (Mac) Type: Preferences: Open User Settings (JSON) Click the option to open your settings.json file.   Step 2: Add Code Runner Terminal Settings Inside the JSON file, add these lines: “code-runner.runInTerminal”: true, “code-runner.clearPreviousOutput”: true These settings will: Make Code Runner use the integrated terminal (which supports input) Clear the old output before running new code Example Full Settings: { “editor.mouseWheelZoom”: true, “files.autoSave”: “afterDelay”, “workbench.iconTheme”: “material-icon-theme”, “code-runner.runInTerminal”: true, “code-runner.clearPreviousOutput”: true } ⚠️ Make sure commas are placed correctly between each line.   Run Your Program with Input Support Open any .c or .cpp file. Click the Run Code button from Code Runner (▶️). The program now runs in the Terminal, and scanf() will work! You can now input values from your keyboard just like a normal console program. Works for C, C++, Python, Java, and More This method isn’t just for C. It works for any programming language where input is needed — such as: Python (input()) Java (Scanner) C++ (cin) C (scanf())   Final Thoughts Running your code in the VS Code terminal instead of the OUTPUT tab is crucial for working with user input. With just one setting, you fix the issue and make your VS Code environment work properly for all interactive programs. Got Stuck? Let me know in the comments if it worked or if you want a full setup guide for C programming in VS Code (with MinGW/gcc)!

How to Install GCC Compiler on Windows Using MSYS2 (Step-by-Step Guide)

Terminal showing MSYS2 installation and GCC version output on a Windows PC, used for setting up a C compiler.

How to Install GCC Using MSYS2 on Windows Great choice! MSYS2 is a powerful and flexible environment for GCC development on Windows. Here’s a step-by-step guide to install GCC using MSYS2: How to Install GCC Using MSYS2 on Windows Step 1: Download and Install MSYS2 Go to the official MSYS2 website: 👉 https://www.msys2.org Download the installer for 64-bit Windows: msys2-x86_64-XXXXXX.exe (where XXXXXX is the version number) Run the installer and install MSYS2 to a simple directory like: C:\msys64   Step 2: Update MSYS2 Package Database Open the MSYS2 MSYS terminal from the Start menu (search for MSYS2 MSYS). Run the following command to update the core system: pacman -Syu If you’re prompted to close the window after this update, do so. Then reopen MSYS2 MSYS and run: pacman -Su Step 3: Install the GCC Compiler (C/C++) In the MSYS2 terminal, install GCC with: pacman -S mingw-w64-x86_64-gcc This installs the 64-bit version of GCC (recommended). If you need 32-bit for some reason, use: pacman -S mingw-w64-i686-gcc Step 4: Use GCC Open the terminal: MSYS2 MinGW 64-bit from the Start Menu (this is important — don’t use the plain “MSYS” terminal for compiling). In that terminal, test GCC: gcc –version Now compile a simple C program: Create a file called hello.c: #include <stdio.h> int main() { printf(“Hello, MSYS2!\n”); return 0; }   Compile and run: gcc hello.c -o hello.exe ./hello.exe   Tip: Optional Useful Packages You can also install other useful tools like: pacman -S make gdb git vim