How to get string words separate? Separate each word from string of /share/test/ Here is simple code snippet which also demonstrate use of string token ( strtok() function) ; Below is simple C code; #include #include int main() { char df_buf[120]; char *name1,*result; int i; char *tmp; char str_array[7][50]; strcpy(df_buf,"/share/test/path/"); result=strtok(df_buf,"/"); //printf("%s\n",result); while(result!=NULL) { tmp=strdup(result); strcpy(str_array[i],tmp); result=strtok(NULL,"/"); printf("%s and %s\n",result,tmp); i++; } printf("i=%d\n",i); printf("%s\n",str_array[0]); printf("%s\n",str_array[1]); printf("%s\n",str_array[2]); return 0; } The output will be share test path ie /share/test/path string is separated into words;
This is my dashboard for Linux notes, programs, Embedded Linux from porting to board bring up..and All about my learning on Linux.