kfries@kfries-laptop:tmp$ cat ex2.c #include #include int main (int argc, char **argv) { int argcount = 1; int mode; while (argcount < argc) { if (strcmp(argv[argcount], "-mode1") == 0) { argcount++; printf("Mode 1 Parameter = %s\n", argv[argcount++]); mode = 1; } else if (strcmp(argv[argcount], "-mode2") == 0) { argcount++; printf("Mode 2 Parameter = %s\n", argv[argcount++]); mode = 2; } else { printf("Unknown command %s\n", argv[argcount]); exit(1); } } printf("End of program in mode %d\n", mode); } kfries@kfries-laptop:tmp$ gcc -o ex2 ex2.c kfries@kfries-laptop:tmp$ ./ex2 -mode1 hello Mode 1 Parameter = hello End of program in mode 1 kfries@kfries-laptop:tmp$ ./ex2 -mode2 world Mode 2 Parameter = world End of program in mode 2 kfries@kfries-laptop:tmp$ ./ex2 -mode3 foobar Unknown command -mode3 kfries@kfries-laptop:tmp$ Kevin Fries On Mon, 2011-12-19 at 15:48 -0700, Michael Havens wrote: > #include > int main (int argc, char * argv[]) > { > int argcount=1; /* argv 1 is the first parameter */ > int mode; > while(argcount < argc ) > { > if(strcmp(argv[argcount],"-mode1") == 0) > { > argcount++; > printf("mode 1 parameter = %s\n",argv[argcount ++]); > mode =1; > } > else if (strcmp(argv[argcount],"-mode2") == 0) > { > argcount++; > printf("mode 2 parameter = %s\n",argv[argcount ++]); > mode =2; > } > else if(strcmp(argv[argcount],"-help") == 0) > { > argcount++; > printf("Help mode\n"); > } > else > { > printf("unknown command %s\n",argv[argcount]); > exit(1); > } > } > printf("end of program in mode %d\n",mode); > } --------------------------------------------------- PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us To subscribe, unsubscribe, or to change your mail settings: http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss