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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -