
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
argc loop . . . . . (was: Re: [tlug] Re: font encoding question)
Jim writes:
> "Stephen J. Turnbull" wrote:
>
> > for (i = 0; i <= argc; ++i)
> > printf ("There's nothing wrong with Unicode for Japanese.\n");
>
> Even though there is no harm since argv[argc] is a null pointer
> and *argv[argc] is not accessed, "<= argc" is fingernails on a
> chalkboard, neverminding the novel use of argc to control non-argv stuff.
Aww, cantcha take a joke?
> If one is going to loop on argc, the C idiom is preferred:
>
> for (i=0;i<argc;i++)
>
> Also tolerable, but less readable, would be:
>
> while (*argv++!=(char *)0)
Danger, Will Robinson! Danger! Fencepost error! These programs
produce too little output!
If you insist on accessing the argv array, the correct idiom is
do { ... } while (*argv++ != NULL);
And yes, the arguments are supposed to be entered individually. No
fair using `seq', this is a punishment assignment. ;-)
Home |
Main Index |
Thread Index