Reputation: 27360
I have a simple c program, with prints something to screen. When I debug the program I can see the DEBUG CONSOLE, however as soon as I use fgets I don't see any output. Where does my program run when debugging using VS Code?
If I just run my compiled .exe, everything is printed as expected.
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello World!\n");
printf("Enter your name\n");
char name[100];
// fgets(name, sizeof(name), stdin); // as soon as I uncomment this, no output is in the output console
printf("You name %s", name);
return 0;
}
my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/app.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]
}
Upvotes: 0
Views: 6153
Reputation: 27360
Just add externalConsole": true
to you configuration in launch.json.
For example:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "cl.exe build active file",
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
Upvotes: -2
Reputation: 7726
One solution may solve your issue.
tasks.json
and launch.json
from VSCodeYou don't need to do any type of coding for this, just follow the steps:
tasks.json
and launch.json
located in .vscode
folderF5
(debugging shortcut) again focusing on that C program file, you'll see something like:GCC
(since you're trying to debug a C program and ensure the compiler is installed into your system).launch.json
created automatically by VSCode as shown below:Note: Keep the
preLaunchTask
configuration in your mind (located at the bottom-most of the config).
F5
again (this time, for creation of tasks.json
) you'll get something shown below, simply select Configure Tasks:tasks.json
, edit the label
to the name you've selected in § 4 (remember that name
). In other words, launch's preLaunchTask
and tasks' label
should be the same. Process shown below:And now, you can make a successful debug. A working example:
Upvotes: 0