Can someone help me with the getopt function?
When I do the following in main:
char *argv1[] = {\"testexec\",\"-?\"};
char *argv2[] = {\"testexec\",\
argv1 and 2 must end in 0:
char* argv1[] = {"par1", "par2", 0};
Edit: OK, I read the getopt man page and I found this:
The variable optind is the index of the next element to be processed in argv. The system initializes this value to 1. The caller can reset it to 1 to restart scanning of the same argv, or when scanning a new argument vector.
So, making optind=1 between the two calls at getopt makes it work as expected.