happyvalley said:
I just wonder how to pass arguments to this function with a char**
void oldmain(int argv, char**argc)
Those names are the opposite of the traditional names, and are
extremely likely to lead to confusion.
{
........
}
void main(void)
main() always, always returns int. In C++, it has never been allowed to
return anything else. Your implementation may allow you to get away
with this, but the moment you write such a thing, it's no longer C++,
and not topical to this newsgroup. You don't even need to write a
return statement, since a zero-return is implicit otherwise: just
change the first "void" to an "int".
{
int argv;
char ** argc;
See above about confusing names...
string cmd[ ] = {"hello", "again", "again"};
// ????????? how to populate cmd[] into **argc
oldmain(argv, argc);
}
how to populate cmd[] into argc, the number of string in cmd[] is not
fixed.
thanks
I'm not sure you've given us enough information to answer your
question. First off: why must it be an array of std::string's (which is
what I'm assuming you're using, though you neither #included the
appropriate headers nor imported the appropriate name std)? Is it
something user-specified, or what?
If I had full control over your main() above, I'd have simply written
it with:
int argc;
char *argv[] = {"hello","again","again"};
And passed that argv to oldmain(). (Note that the above involves some
deprecated conversions from const char* to char*, and may not be
portable to future versions of the C++ language.)
What did you mean by "the number of [strings] in cmd[] is not fixed"?
The number of elements in any array is fixed. Perhaps your real code
doesn't use an array?
In either case, if you're really stuck with the input being C++
std::string's, then you cannot avoid copying them into a new array of
C-strings (the space for which you will need to allocate yourself). If
you're not really using an array for the srings (a std::vector,
perhaps), then you will proably need to allocate the space for the
array of (char*)s as well.
-Micah