Can some please tell me why this doesn't work because I just can't fingure it out.
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if ("help" == argv[1]) { system("help.exe"); } printf("%s\n",argv[1]); }
Can some please tell me why this doesn't work because I just can't fingure it out.
Code:#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { if ("help" == argv[1]) { system("help.exe"); } printf("%s\n",argv[1]); }
It does not work, or it won't compile? Be sure to check argc first.
Also return 0;
Last edited by JoshG; 08-16-2002 at 04:50 PM.
gcc -lalleg
http://www.ciusa.net/~jrgrant/
Logically, it should be:
if(argv[1] == "help")
However, you can't compare strings like that. Use strcmp().
Try not.
Do or do not.
There is no try.
- Master Yoda
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Try this, though I dunno what the results will be or if it will work.
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { if(argc == 2) { if((strcmp(argv[1], "help")) == 0) printf("help was entered as an argument\n"); else printf("%s was entered as an argument\n", argv[1]); } else printf("no argument enetered, or more than one argument entered.\n"); return 0; }
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P