[Coco] Can I pass command line parameters to a cmoc program from os9 ?

coco at jechar.ca coco at jechar.ca
Sat Jul 22 18:18:06 EDT 2023


Sean
CC:all

Thanks Sean
This is good does pretty much what I want.

Some notes for CMOC though
I needed to replace #include <stdio.h>
with
#include <stdarg.h>
#include <coco.h>

Otherwise it worked just like expected except that
argv[0] came out as "" not "cc" or "main".

Charlie

On 2023-07-22 16:27, Sean Conner via Coco wrote:
> 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