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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -