Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22009

Visual Studio Code: arguments not passed to C command line application

$
0
0

I have started using Visual Studio Code on Kali Linux 2019.4. I am compiling C code using the Code Runner extension. I am experiencing an issue where arguments passed to the application via "args": ["String1", "String2"] in launch.json, are not getting passed to the application as is indicated in the below output:

Output:

[Running] cd "/home/user/Desktop/test/"&& gcc test.c -o test && "/home/user/Desktop/test/"test
Length of argv is: 1
Arg 1 is: /home/user/Desktop/test/test
Arg 2 is: (null)
Arg 3 is: GJS_DEBUG_TOPICS=JS ERROR;JS LOG
Missing argument

[Done] exited with code=1 in 1.166 seconds

What could be the reason that the arguments are not getting passed? I have included the C code and launch.json contents below:

C code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
    printf("Length of argv is: %d\n", argc);
    printf("Arg 1 is: %s\n", argv[0]);
    printf("Arg 2 is: %s\n", argv[1]);
    printf("Arg 3 is: %s\n", argv[2]);

    if (argc < 3)
    {
        printf("Missing argument\n");
        exit(1);
    }

    printf("Arg 1 is %s\n", argv[1]);
    printf("Arg 2 is %s\n", argv[2]);

    return 0;
}

launch.json:

"version": "0.2.0",
    "configurations": [
        {
            "name": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": ["String1","String2"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

Viewing all articles
Browse latest Browse all 22009

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>