How can a FILE* (pointer to a struct) be tested (if == NULL)?

Posted by m4design on Stack Overflow See other posts from Stack Overflow or by m4design
Published on 2010-06-02T12:17:22Z Indexed on 2010/06/02 12:23 UTC
Read the original article Hit count: 206

Filed under:
|
|
|

I was playing around with C, anyways I was thinking how can file pointer (which points to a struct type), be tested if NULL as for instant:

FILE *cfPtr;
if ( ( cfPtr = fopen( "file.dat", "w" ) ) == NULL )

I tried to do that myself, but an error occurs.

struct foo{
    int x;
};

struct foo bar = {0};

if (bar == NULL)
    puts("Yay\n");
else
    puts("Nay");

error C2088: '==' : illegal for struct

Here's the FILE deceleration in the stdio.h file:

struct _iobuf {
        char *_ptr;
        int   _cnt;
        char *_base;
        int   _flag;
        int   _file;
        int   _charbuf;
        int   _bufsiz;
        char *_tmpfname;
        };
typedef struct _iobuf FILE;

© Stack Overflow or respective owner

Related posts about c

    Related posts about file