This is my simple program
#include <stdio.h>
int main(int argc, char *argv[]){
printf("%dn", argc);
for(int i=1; i<argc; i++) printf("%sn", argv[i]);
return 0;
}
If I compile with terminal and run
gcc -o test test.c
./test foo bar
I get
3
foo
bar
so works perfectly. Now I would like debug this program passing arguments <"foo"> <"bar"> but i don’t understand how.
I tried with CTRL + SHIFT + P -> "C/C++: edit Configurations (JSON)" and adding the line
"compilerArgs": ["bar", "foo"]
but still doesn’t work. Debugger says "argc: 1" when it should be 3
enter image description here
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name":"gcc - Build and debug active file",
"type":"cppdbg",
"request": "launch",
"program": "${workspaceRoot}/Assignment1/",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"MIMode": "gdb",
"externalConsole": false
}
]
}
task.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
],
"version": "2.0.0"
}
What I’m doing wrong?
2
Answers
I solved, I missed to add "/test" in lauch.json:
now everything works
put them right