Converting a space seperated string to an array of pointers in C -
i have string this: "arg1 arg2 arg3" want send exec. execvpe takes array of pointers command arguments. there way can take arg1, arg2, , arg3 , set them array of pointers?
i've separated them strtok, not sure next... have *argv[x] waiting them.
thank you, j
strtok
hands pointers each item, need take values returned strtok
, place them in argv
array.
char *str = "arg1 arg2 arg3"; char *argv[3]; int = 0; argv[i] = strtok(args, " "); while (argv[i] != null) { i++; argv[i] = strtok(null, " "); }
c
No comments:
Post a Comment