Lets say I have a function:
void split_path_file(char** p, char** f, char *pf)
{
//malloc and set *p to file path, malloc and set *f to file name
//p
int
stripfilenameandpath (char *path, char *onlypath, char *onlyfilename)
{
/*
documentacao
path = path com path e arquivo
onlypath = somente o path
onlyfilename = somente o arquivo sem o path
*/
int ret;
int i;
int p;
char temp[255];
char *fixo;
#ifdef WIN32
const int separator = '\\';
#else
const int separator = '/';
#endif
fixo = path;
if (path == NULL)
{
if (onlypath != NULL)
{
memset (onlypath, 0, 1);
}
if (onlyfilename != NULL)
{
memset (onlyfilename, 0, 1);
}
return 1;
}
ret = strlen (path);
if (!ret)
{
if (onlypath != NULL)
{
memset (onlypath, 0, 1);
}
if (onlyfilename != NULL)
{
memset (onlyfilename, 0, 1);
}
return 0;
}
for (i = 0; i -1; i--)
{
if (temp[i] == separator)
{
temp[i + 1] = 0;
break;
}
p++;
}
p = ret - p;
fixo += p + 1;
if (onlypath != NULL)
{
strcpy (onlypath, temp);
}
if (onlyfilename != NULL)
{
strcpy (onlyfilename, fixo);
}
return 0;
}