How can I handle this string concatenation in C in a reusable way
- by hyphen this
I've been writing a small C application that operates on files, and I've found that I have been copy+pasting this code around my functions:
char fullpath[PATH_MAX];
fullpath[0] = '\0';
strcat(fullpath, BASE_PATH);
strcat(fullpath, subdir);
strcat(fullpath, "/");
strcat(fullpath, filename);
// do something with fullpath...
Is there a better way? The first thought that comes to mind is to create a macro but I'm sure this is a common problem in C, and I'm wondering how others have solve it.