I have this function which gets the given directory and filename and concat it by checking if the end of the directory contains / character and concatenating the string's for condition. My problem is that when i give the function a directory name and filename if the filname has \ it does not concat the string correctly. but when if the file does not contain any \ the output will be given.How can i fix the issue?.
Here is my C Code.
char * find_endwith_slash(char *dir_path, char *file_name)
{
char full_path[1024];
if (dir_path[strlen(dir_path) - 1] != '/')
{
sprintf(full_path, "%s/%s", dir_path, file_name);
}
else
{
sprintf(full_path, "%s%s", dir_path, file_name);
}
char * full_name = malloc(strlen(full_path) * sizeof(char));
full_name = strdup(full_path);
return full_name;
}