I believe the problem is how you parented the expression.
I made a code with several attribution combinations, the problem in your case is that the second part of the expression was indice = fopen(...) == NULL
and not (indice = fopen(...)) == NULL
.
So by priority, your expression would be equal to indice = (fopen(...) == NULL)
. And there, you’re assigning an integer value to the pointer for the structure FILE
, generating the error.
Below follows the code tested:
#include <stdio.h>
int main(void) {
FILE* mestre, *indice;
mestre = fopen("//home//vitor//Desktop//mestre.bin", "ab");
indice = fopen("//home//vitor//Desktop//indice.bin", "ab");
if (mestre == NULL || indice == NULL){
printf("Erro na abertura do arquivo");
}
if((mestre = fopen("//home//vitor//Desktop//mestre.bin", "ab")) == NULL) {
printf("Erro na abertura do arquivo");
}
if(((mestre = fopen("//home//vitor//Desktop//mestre.bin", "ab")) == NULL) ||
((indice = fopen("//home//vitor//Desktop//indice.bin", "ab")) == NULL)) {
printf("Erro na abertura do arquivo");
}
if (((mestre = fopen("//home//vitor//Desktop//mestre.bin", "ab"))==NULL) ||
((indice = fopen("//home//vitor//Desktop//indice.bin", "ab")==NULL))){
printf("Erro na abertura do arquivo");
}
return 0;
}
You know the function
fopen
returns a pointer to the structureFILE
no? Take a look at the documentation: http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html. Maybe you are confusing this with the functionopen
offcntl.h
that returns theFile Descriptor
(http://gd.tuwien.ac.at/languages/c/programming-bbrown/c_075.htm).– Wakim
Yes, I just forgot to comment there, the master and Dice are declared as FILE *master, *Input and correctly receiving the file, I would just like to know why Warning. including in the documentation has an example of what I am doing , at the end in Opening a file.
– Vitor Figueredo