I wrote a program that can accepts arguments from the command line, which are supposed to be a number, an operator (of length 1) and another number:
int main(int argc , char *argv[]){
if (argc < 4){
printf("Too few arguments (4 required)");
return -1;
}
char *a = argv[1];
char b = *argv[2];
char *c = argv[3];
printf("%s %c %s = ...", a, b, c);
return 0;
}
Which seems to work fine, such as when I pass 110 + 11
I get:
110 + 11 = ...
But if I pass something with the operator *
, like 110 * 11
, it messes up:
110 b c_nums.cbp = ...
The only thing that seems to work is if I replace *
with ^*
or '*'
and change char b = *argv[2];
to char b = *(argv[2]+1);
I'm assuming this has to do with how cmd or whatever formats commands, but how can I fix this without always passing ^<op>
instead of <op>
?
Edit: Ok, so it looks like "*"
works in cmd but not Code::Blocks for some reason.