见How to concatenate 2 strings in C?。您也可以使用strcat
。
检出this教程。
在这样的一个例子是:
/* Example using strcat by TechOnTheNet.com */
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
/* Define a temporary variable */
char example[100];
/* Copy the first string into the variable */
strcpy(example, "TechOnTheNet.com ");
/* Concatenate the following two strings to the end of the first one */
strcat(example, "is over 10 ");
strcat(example, "years old.");
/* Display the concatenated strings */
printf("%s\n", example);
return 0;
}
你的情况,那就是:
char file_name[200 + 200];
file_name [0] = '\0' // To make sure that it's a valid string.
strcpy (file_name, str); // Concatenate `str` and `file_name`
strcat(file_name, str2); // Concatenate `str2` and `file_name`
out_file = fopen(file_name, "w"); // Open the file.
而且,这要归功于指出了一些错误 'laerne'。
您不能在C中使用'+'运算符连接字符串。为此使用'strcat'或任何其他适当的函数。 – fuz
因为,@FUZxxl说,你将不得不使用'strcat'来连接字符串。 –
阅读本文[如何连接C中的2个字符串?](http://stackoverflow.com/questions/8465006/how-to-concatenate-2-strings-in-c) –