Good morning,
Is there a simple way of converting a string (char *s) to an array of the type argv[] (console mode)? I'm trying to convert a console program I made to a dll.
Kind regards,
JKepler
Good morning,
Is there a simple way of converting a string (char *s) to an array of the type argv[] (console mode)? I'm trying to convert a console program I made to a dll.
Kind regards,
JKepler
Like this?
Code:char *s1 = "hello"; char s2[] = "world"; char *myArgv[] = { s1, s2, NULL };
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hi
I was thinking something like this:
But I'm not sure if I'm thinking straight...Code:char *string = "Mark,John,Mathew"; char *argv[10]; int i=0; argv[i] = strtok(string,","); while(argv[i]!=NULL) { argv[++i] = strtok(NULL,","); }
Can the string be *string or must it be string[]?
JKepler
string must be an array if you intend to chop it up with strtok().
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.