Assuming that every result you get will have this trailing slash, you can simply remove it from the final output. In the code snippet below, I conditionally check that it resulthas at least one character and that the last character is a slash. If these conditions are true, I remove the slash.
char * result = buildPath(&node3, false);
if (result && *result) {
if (result[strlen(result) - 1] == '/')
result[strlen(result) - 1] = 0;
}
Update:
Here is a solution to your problem that modifies the algorithm itself. Try changing the code to the following:
int firstCall = 1;
do {
if(!use_register_name)
{
use_register_name=true;
node = node->parent;
continue;
}
char *name = strdup(node->name);
if (firstCall) {
firstCall = 0;
}
else {
strcat(buffer,"/");
}
strrev(name);
strcat(buffer,name);
node = node->parent;
free(name);
} while (node != NULL &&strcmp(node->name,"root")<0);
OP:
buffer = "/dlihcdnarg" // note carefully this leading (really trailing) slash
buffer = "/dlihcdnarg/dlihc"
- , :
"child/grandchild/"
node ( ) , :
"child/grandchild"