thanks for your reponse ill try to make sense out of that
the program takes the pointer to pointer and the int and gets its
parameters like this
while ((ch = getopt(argc, argv,
"b:c
de:f:F:hHk:lmn
Pr:sS:tT:uUv:x:z:")) != -1)
'getopt' is not a standard C function, and so it's off-topic here.
That's not just zealous topicality guidance, either -- I really have
no idea how 'getopt' works, and I don't care. But I can make some
assumptions, most of them implicit, and let you puzzle out what works
and what doesn't.
i would like to give it a string rather than the pointer to pointer. i have
done this in the main program and it compiles but i cant get the function
to run
int main(int argc, char* argv[])
{
char line[100] = "-s -T 1002\n";
int t = zcommand(1, &line);
Where 'zcommand' is the old 'main' function, no doubt. Okay, I'm
not surprised that it didn't work. I recommend that you take a good
look at the last public C draft standard, N869 (which you can Google
for; it comes in plain text as n869.txt[.gz]). It has a section
somewhere detailing exactly what the implementation guarantees to
be present in 'argc' and 'argv' -- and thus what *you* need to
guarantee will be present in *your* "fake" argc and argv.
I would quote N869 right here, but I'm on a slow connection this
week. Maybe someone else will. Anyway, search the file for the
words 'argc' and 'argv' and I bet you'll find it.
You [probably] need to split up those arguments in that string
literal, like this [but I don't know how lenient 'getopt' might
be on your platform -- maybe it's a non-issue]:
char *line[] = {"dummy", "-s", "-T", "1002", NULL};
int t = zcommand(4, line);
If this *is* the issue [consult your 'getopt' documentation, such
as "man getopt" or your compiler manual], then you might need to
write some code to split up the "command-line arguments" yourself.
That is, a function that can take the input
"-s -T 1002\n"
and produce the output
{"dummy", "-s", "-T", "1002", NULL}
If it turns out you do need such a function, check Google for
"command line argument parsing" or post to a group like
comp.sources.wanted. (comp.lang.c is *not* the place to ask other
people to write whole big functions for you.)
HTH,
-Arthur