How to check of successful opening of a file pointer?

When using FILE * fin;
how do you check to see if opening of a file was successful or if the current file is currently open?

this doesn't work:
 
     if ((fin = fopen("test.txt", "r") ) )


I get a segmentation fault.

and of course I can't use is_open because its not a member function.
1
2
3
4
5
FILE *fin;
//...
fin = fopen("text.txt", "r");
if (fin == 0)
    printf("failed to open file\n");
Topic archived. No new replies allowed.