69,371
社区成员
发帖
与我相关
我的任务
分享
char cache[] = "cmd --opt1 par1 arg1 --opt2 par2 --flg1 --flg2 arg2 arg3"
char *argv[0x40] = {};
char *pin, *psv;
int argc;
for ( argc=0, pin=cache; (argv[argc] = strtok_r( pin, " ", &psv )) != NULL; argc++, pin=NULL );
// you have got argc and argv
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}