[Coco] Can I pass command line parameters to a cmoc program from os9 ?
Sean Conner
sean at conman.org
Sat Jul 22 16:27:36 EDT 2023
It was thus said that the Great coco--- via Coco once stated:
> All
>
> Wanted to know how to pass a parameter from the OS9
> command line into a CMOC generated program. Found no
> usefull examples in the CMOC manual ...
Try the following program:
======================
#include <stdio.h>
int main(int argc,char *argv[])
{
int i;
for (i = 0 ; i < argc ; i++)
{
printf("command line argument %d: '%s'\n",i,argv[i]);
}
return 0;
}
======================
In C, the function main() gets the command line broken up by whitespace
and each "argument" in the argv[] array. By convention, argv[0] is the
program name itself.
The C standard doesn't define the getopt.h header---that is specified by
POSIX (read: water downed Unix). If getopt.h doesn't exist for your system,
then you'll have to write code to look through the argv[] array passed to
main().
-spc
More information about the Coco
mailing list