【发布时间】:2012-02-02 22:17:40
【问题描述】:
我正在尝试将相对路径传递给 fopen(),但它似乎无法找到该文件。我需要这个才能在 Linux 上工作。 文件名(例如:t1.txt)保存在一个数组中。所以我需要的只是相对路径的“前面部分”。
这是我的代码:
// Use strcat to create a relative file path
char path[] = "./textfiles/"; // The "front part" of a relative path
strcat( path, array[0] ); // array[0] = t1.txt
// Open the file
FILE *in;
in = fopen( "path", " r " );
if (!in1)
{
printf("Failed to open text file\n");
exit(1);
}
【问题讨论】: