「文字列」が実際にメモリ内でどのように表現されるかを考える必要があります。C では、文字列は割り当てられたメモリのバッファであり、0 バイトで終了します。
filename |p|i|c|t|u|r|e|0|
directory |/|r|d|/|0|
必要なのは、両方の文字列のメモリ内容と最後の 0 バイトを一緒にコピーするための新しいメモリ空間です。
path |p|i|c|t|u|r|e|/|r|d|/|0|
これにより、次のコードが得られます。
int lenFilename = strlen(filename); // 7
int lenDirectory = strlen(directory); // 4
int lenPath = lenFilename + lenDirectory; // 11 I can count
char* path = malloc(lenPath + 1);
memcpy(path, filename, lenFilename);
memcpy(path + lenFilename, directory, lenDirectory);
path[lenPath] = 0; // Never EVER forget the terminating 0 !
...
free(path); // You should not forget to free allocated memory when you are done
(このコードには 1 ずつずれている可能性があります。実際にはテストされていません。午前 01:00 です。寝る必要があります!)