Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
September 28, 2003 Q: char[][] args to C char**argv | ||||
---|---|---|---|---|
| ||||
How do we do that? D source: extern(C) c_parse_args((int argc,char **argv); void main(char[][] args) { char** argv = ?; int argc = args.length c_parse_args(argc, argv); } Ant |
September 28, 2003 Re: char[][] args to C char**argv | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | char** argv = new char*[args.length]; int i = 0; foreach (char[] p; args) { argv[i++] = cast(char*)p; } "Ant" <Ant_member@pathlink.com> wrote in message news:bl5s9q$140q$1@digitaldaemon.com... > How do we do that? > > D source: > > extern(C) c_parse_args((int argc,char **argv); > > void main(char[][] args) > { > char** argv = ?; > > int argc = args.length > > c_parse_args(argc, argv); > } > > Ant > > |
September 28, 2003 Re: Q: char[][] args to C char**argv | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | Ant wrote: > > How do we do that? > > D source: > > extern(C) c_parse_args((int argc,char **argv); > > void main(char[][] args) > { > char** argv = ?; > > int argc = args.length > > c_parse_args(argc, argv); > } This should do the job: import string; alias char [] String; char** ArgsRetArgv(String [] args) { char* [] argv; argv.length=args.length+1; for(int i; i<args.length; i++) { argv[i] = (char *)args[i]; } return argv; } int main (String [] args) { char** argv=ArgsRetArgv(args); // c_parse_args(args.length,argv); return 0; } Its based on the (tested) assumption, that args consists of slices on the existing '\0'-terminated argv-buffer. -- Helmut Leitner leitner@hls.via.at Graz, Austria www.hls-software.com |
September 28, 2003 Re: char[][] args to C char**argv | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | In article <bl62sm$1dq0$1@digitaldaemon.com>, Walter says... > >char** argv = new char*[args.length]; >int i = 0; >foreach (char[] p; args) >{ > argv[i++] = cast(char*)p; >} > Thanks. Maybe this couldl be on one of the C to D pages. Thanks also to Helmut. Ant |
Copyright © 1999-2021 by the D Language Foundation