#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WINDOWS
#define SEPARATOR '\\'
#else
#define SEPARATOR '/'
#endif
char *path_join(char *path1, char *path2)
{
char *new_path = malloc(strlen(path1) + strlen(path2) + 1);
if (path2[0] == SEPARATOR)
sprintf(new_path, "%s", path2);
else
sprintf(new_path, "%s%s", path1, path2);
return new_path;
}
int main(int argc, char *argv[])
{
if (argv[1] && argv[2])
{
char *path = path_join(argv[1], argv[2]);
printf("%s\n", path);
free(path);
}
else printf("Usage: ./path_join path1 path2\n");
return 0;
}