I have the following C application:
#include <stdio.h>
#include <string.h>
int main() {
char name[10];
printf("What is your name?\n");
fflush(stdout);
fscanf(stdin, "%s", name);
printf("Your name is %s.\n", name);
return 0;
}
I am running it with:
- Visual Studio Code 1.48.2
- C/C++ (Extension for Visual Studio Code) 0.29.0
- Code Runner (Extension for Visual Studio Code) 0.11.0
- MinGW (mingw32-base) 2013072200
When I hit CTRL+F5 (effectively, Run Without Debugging), I see the prompt, What is your name?
in the Debug Console. I try to type my name into the Debug Console, and it gives the following error: Unable to perform this action because the process is running.
How can I read from stdin
using the integrated terminal?
Here is my launch.json
configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
I was able to get it to take input from stdin
using the external console by setting "externalConsole": true,
in the above configuration, but I am looking for a way, if possible, to be able to simply write my name in one of the integrated IDE console tabs so that I don't need to launch an external console.