training
Michael Havens
bmike1 at gmail.com
Tue Dec 20 10:35:10 MST 2011
thanks, kevin. I'm working on learning Ruby right now.
On Mon, Dec 19, 2011 at 11:41 PM, Kevin Fries <kevin at fries-biro.com> wrote:
> You did not have stdlib.
>
> You need to include both stdio to get printf and stdlib to get exit.
>
> C has a very small set of functions built in. You can add in all kinds of
> additional functionality. In order to do that, you need to add the
> headers. Those headers are collected together in the header files.
>
> C has an exit function that is defined, but is not really defined for
> use. Standard Lib redefines the exit command you used. Without that
> header, the prototype of the exit command as defined and as used did not
> match. By adding the header at the top, the use and.prototype are now in
> sync and the program compiles.
>
> Good Luck
> Kevin
> On Dec 19, 2011 11:05 PM, "Michael Havens" <bmike1 at gmail.com> wrote:
>
>> so please, do share.... why wouldn't my version compile?
>>
>>
>>> > On Mon, Dec 19, 2011 at 4:04 PM, Kevin Fries <kevin at fries-biro.com>
>>> wrote:
>>> >>
>>> >> kfries at kfries-laptop:tmp$ cat ex2.c
>>> >> #include <stdio.h>
>>> >> #include <stdlib.h>
>>> >>
>>> >> 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 at kfries-laptop:tmp$ gcc -o ex2 ex2.c
>>> >> kfries at kfries-laptop:tmp$ ./ex2 -mode1 hello
>>> >> Mode 1 Parameter = hello
>>> >> End of program in mode 1
>>> >> kfries at kfries-laptop:tmp$ ./ex2 -mode2 world
>>> >> Mode 2 Parameter = world
>>> >> End of program in mode 2
>>> >> kfries at kfries-laptop:tmp$ ./ex2 -mode3 foobar
>>> >> Unknown command -mode3
>>> >> kfries at kfries-laptop:tmp$
>>> >>
>>> >>
>>> >>
>>> >> Kevin Fries
>>> >>
>>> >>
>>> >>
>>> >> On Mon, 2011-12-19 at 15:48 -0700, Michael Havens wrote:
>>> >> > #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);
>>> >> > }
>>> >>
>>> >> ---------------------------------------------------
>>> >> 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
>>> >
>>> >
>>> >
>>> > ---------------------------------------------------
>>> > 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
>>> ---------------------------------------------------
>>> 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~(-:
>>
>> ---------------------------------------------------
>> 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
>>
>
> ---------------------------------------------------
> 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/20111220/7a022d3d/attachment.html>
More information about the PLUG-discuss
mailing list