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.