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
Post a Comment