PREV INDEX NEXT

Author: Stan Eisenstat
Subject: argv[] must be NULL-terminated
Date: Tuesday, 29 Sep 2020, 10:40:36


The argc arguments to the program are stored in the
argv[] array passed to main().  However, the length of
argv[] is argc+1, not argc, because by convention
argv[argc] = NULL.

The argv[] array in the CMD struct mimics this behavior.
When mallocCMD() creates a CMD, it sets argv to a
pointer to a block of malloc()-ed storage large enough
to hold ONE char* and sets its value to NULL.

When you add the arguments of a [simple] to argv[], you
must realloc() that storage (or malloc() new storage and
free() the old) accordingly, and then you must set
argv[argc] = NULL.

--Stan-
PREV INDEX NEXT