c - Split string into tokens and save them in an array -


how split string tokens , save them in array?

specifically, have string "abc/qwe/jkh". want separate "/", , save tokens array.

output such that

array[0] = "abc" array[1] = "qwe" array[2] = "jkh" 

please me

#include <stdio.h> #include <string.h>  int main () {     char buf[] ="abc/qwe/ccd";     int = 0;     char *p = strtok (buf, "/");     char *array[3];      while (p != null)     {         array[i++] = p;         p = strtok (null, "/");     }      (i = 0; < 3; ++i)          printf("%s\n", array[i]);      return 0; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -