Due to operator precedence rules, the condition is interpreted as fd=(fopen(fileName,"r") == NULL) . The result == is an integer, fd is a pointer, so an error message.
Consider the "extended" version of your code:
FILE *fd; int ok; fd = fopen(fileName, "r"); ok = fd == NULL;
Do you expect the last line to be interpreted as (ok = fd) == NULL or ok = (fd == NULL) ?
source share