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;
share
test
path
ie /share/test/path string is separated into words;
Here is simple code snippet which also demonstrate use of string token (strtok() function);
Below is simple C code;
The output will be#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;
}
share
test
path
ie /share/test/path string is separated into words;
Comments