Reputation: 183
I have a line like the one below, but I need to concat slashes for directories, is there any way to safely concat multiple strings?
// Need to include \\ after windowsDir
FILE *dest = fopen(strcat(windowsDir, filename),"wb");
Upvotes: 0
Views: 454
Reputation: 108978
Supposing there is enough space all around, this works
strcpy(buff, "C:\\foobar");
strcpy(value, "file.txt");
strcat(strcat(buff, "\\"), value);
/* buff now has "C:\\foobar\\file.txt" */
Upvotes: 0
Reputation: 318568
char *buf = malloc(strlen(windowsDir) + 1 + strlen(filename) + 1); // len + \ + len + \0
sprintf(buf, "%s\\%s", windowsDir, filename);
FILE *dest = fopen(buf, "wb");
free(buf);
Upvotes: 5