Re: split a /path/filename into components



Eric wrote:
Is there a C library function that can take a path and break it into its
component parts? I think dos has one called fnsplit but i cant seem to find
an equal in the linux world

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int ArgC,char *ArgV[]) {

char *Ptr;
char path[255],file[64];

Ptr = strrchr(ArgV[1],'/');
strcpy(path,(Ptr == NULL) ? "./" : (Ptr[0]='\0',ArgV[1]));
strcpy(file,(Ptr == NULL) ? ArgV[1] : Ptr+1);

printf("path=%s file=%s\n",path,file);

return 0;

}
.



Relevant Pages