我在C中的程序读取文件中的数据以初始化变量,但它不会打开文件.当它达到fopen时失败.Xcode为fopen和printf输出以下警告.我理解错误,但我不知道如何纠正它,我尝试了许多技巧,但它不会做,任何人都可以帮助我吗?我只想让我的程序打开Try1.txt.
不兼容的指针类型将'char(*)[9]'传递给const char*类型的参数
所以这是我的main函数中的代码:
FILE *infile = NULL;
const char infilename [] = "Try1.txt";
infile = fopen(&infilename, "r");
if (infile == NULL)
{
printf("Failed to open file: %s\n", &infilename);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
请注意,程序在到达if循环之前停止,因为它从不打印.我试图初始化大小,并在我的字符串末尾添加'\ 0'.