I think the problem is the way you put parentheses in the expression.
I made a code with several assignment combinations, the problem in your case is that the second part of the expression is indice = fopen(...) == NULL
and not (indice = fopen(...)) == NULL
.
By priority, its expression would be equal to indice = (fopen(...) == NULL)
. And, you're assigning an integer value to the pointer to the FILE
structure, generating the error.
Below is 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;
}