training

Michael Havens bmike1 at gmail.com
Mon Dec 19 15:48:01 MST 2011


that one compiles and runs.... I can't get the second to compile.

#include <stdio.h>
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);
}

On Mon, Dec 19, 2011 at 3:24 PM, Kevin Fries <kevin at fries-biro.com> wrote:

> On Mon, 2011-12-19 at 15:07 -0700, Michael Havens wrote:
> > I might be grren but I did put the '#include<stdlib.h>' in. In fact I
> > copied the entire file and it didn't compile.
>
> Not sure what was wrong.
>
> I was able to run your example:
>
> kfries at kfries-laptop:tmp$ cat argexample.c
> #include <stdio.h>
>
> int main (int argc, char **argv) {
>   int count;
>   for (count = 0; count < argc; count++) {
>      printf ("argument no %d = %s\n", count, *argv++);
>   };
>
>   return 0;
> }
> kfries at kfries-laptop:tmp$ gcc -o argexample argexample.c
> kfries at kfries-laptop:tmp$ ./argexample hello world
> argument no 0 = ./argexample
> argument no 1 = hello
> argument no 2 = world
>
>
> Hope this helps
> Kevin
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change your mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>



-- 
:-)~MIKE~(-:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.PLUG.phoenix.az.us/pipermail/plug-discuss/attachments/20111219/2c10638a/attachment.html>


More information about the PLUG-discuss mailing list