I'm trying to parse a string in c something like this :
/afolder/secondfolder/thirdone
do a function and that function should return this:
/afolder/secondfolder
I've tryed many things...
int getParentFolder(const char *pPathNewLink, char* TargetDirectory) {
char *dirPath = strrchr(pPathNewLink, '/');
strncpy(TargetDirectory, pPathNewLink, dirPath - pPathNewLink);
return 1;
}
I cannot use operating systems libraries. I got to do it that way.
I tryed calling the function like this :
char * test;
getParentFolder("/var/lib",test);
printf("%s", test);
but I get a seg fault...