0

So I have this C code which gives me different output depending upon where I run it and how I run it. The code is

#include <stdio.h>    // needed to print to the command window screen
#include <stdlib.h>   // ASCII to integer conversion

int main(int argc, char *argv[]) {
    // check for a valid number of inputs.
    if (argc != 1 && argc != 7) {
        printf(
                "Incorrect arguments passed: It is either no arguments for default value (i.e: phase1.exe). ");
        printf(
                "or \"phase1 -r n -c n -v *\". n is number from 1-20.");
        // non-zero return values often indicate different types of failure/
        return -1;
    }

    if (argc != 1) {
        for (int i = 1; i < argc; i++) {
            printf("%s ", argv[i]);
            printf("\n");
            fflush(stdout);
        }
    }
}

If I run the code on Visual Studio with cmd line argument as -r 2 -c 3 -v * The output is as following

-r
2
-c
3
-v
*

which is what I would expect. But now moving to Eclipse CDT

The problem

If I launch the code in run mode with same command line argument I get this

Incorrect arguments passed: It is either no arguments for default value (i.e: phase1.exe).

Meaning Eclipse is somehow omitting the * character in the command line argument so the number of argument passed decreases from 7 to 6. However, if instead of using the run mode, if I use the Debug mode. The code doesn't give me error, but it doesn't give me the right answer either. The output I get from debug mode is this

-r 
2 
-c 
3 
-v 

It doesn't print the star character. I checked the variable window, and it is there the whole time. But for some reason, eclipse doesn't print it. I am not sure whether this eclipse issue or visual studio being extra smart and eclipse doing exactly what I asked it do do.

Goion
  • 923
  • 8
  • 16
  • [Its not the OS it is the shell](https://stackoverflow.com/questions/27098588/argv-sanitizing-wildcards) – Cody Oct 23 '20 at 17:24
  • @Cody Correct me if I am wrong. So Eclipse honors the glob while the VS does not. Is there a way I can make eclipse not think of * as wild card? Also why the debug mode does not throw error similar to run mode? – Goion Oct 23 '20 at 17:34
  • I think I have found the issue of glob https://stackoverflow.com/questions/2718873/the-issue-of-in-command-line-argument. Though I am not sure why debug and run mode behave differently. – Goion Oct 23 '20 at 17:42

0 Answers0