I would like make some complement about the question.

strlcat works when I put all in main instead of using an extra fuction. That is:

main...{
char path[256]
char file1[256]
snprintf(path, 256, "%s", "./test/");
snprintf(file1, 256, "%s", "testtt.dat");
int file1_len = strlen(file1);
strlcat(path, file1, file1_len);
cout << path << endl;
}

The output is ./test/testtt.dat...

SO why this works but previous one???

Thanks
Xiong

Quote:
Originally Posted by dbigbear View Post
I,

I come across a strange problem when using strlcat, as follows:

static int get_path(char *parent, char * file){
int parent_len = strlen(parent);
int file_len = strlen(file);
if(parent_len + file_len > 256) {
return 0;
}
int ret = strlcat(parent, file, file_len);
}

int main(int argc, char *argv[]) {
char path[256];
char file[256];
snprintf(path, 256, "%s", "./parent/");
snprintf(file, 256, "%s", "test.dat");
get_path(path, file);
cout << path << endl;
cout.flush();
}

The output is :

./parent/


The problem is why the output is "./parent/"? Is it supposed to be "./parent/test.dat"?

Thanks
Xiong