Hello,
I am trying to split the unix folder path from the file name that is entered.
For example, if the path entered is "/home/user/temp/asdf.txt"
I want to return 2 things...
Folder name: "/home/user/temp"
File Name: "asdf.txt"
On running this, I get the following output...Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define WORD_COUNT 10 int main (int argc, char *argv[] ) { char text[] = "/The/quick/brown/fox/jumped/over/the/lazy/red/dog"; char *wlist[WORD_COUNT]; /*array of 10 pointers to characters*/ char *nwlist[WORD_COUNT]; int i; printf("text[%s]\n", text); wlist[0] = strtok( text, "/" ); nwlist[0] = strtok( text, "/" ); for ( i=1; i < WORD_COUNT; i++ ) { wlist[i] = strtok( NULL, "/" ); } for ( i=0; i < WORD_COUNT-1; i++ ) { strcat(wlist[i], "/"); printf("\n%s",nwlist[i]); } return 0; }
I have used " \n" to ensure readibility...Code:text[/The/quick/brown/fox/jumped/over/the/lazy/red/dog] The/ / brown/ / jumped/ / the/ /
Kindly help me if i am wrong anywhere...
Thank you.
-Monil



LinkBack URL
About LinkBacks


