Tuesday, January 30, 2018

fopen incompatible type char (*)[9] instead of char(*) in C

My program in C reads data in a file in order to initialise variables but it won't open the file. It fails when it reaches fopen. Xcode outputs the following warning for both fopen and printf. I understand the error but I don't know how to correct it, I tried many tricks but it won't do, can anyone help me out ? I just want my program to open Try1.txt.


Incompatible pointer types passing 'char (*)[9]' to parameter of type const char*'


So this is the code inside my main function :


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;
}

Note that the program stops before reaching the if loop because it never prints. I tried to initialise the size and to add '\0' at the end of my string too.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...