FILE *fp[]; /* is this possible? */

Gary Weimer weimer at ssd.kodak.com
Thu Nov 29 02:21:46 AEST 1990


In article <1990Nov27.131327.21662 at agate.berkeley.edu> labb-4ac at e260-2a.berkeley.edu (superMan (the web dweller)) writes:
>I have the following
>
>FILE *fp[256];
>
>for(i=0;i!=256;i++) fp[i]=fopen(file_name[i],"r+");
>
>but when I look at the value of fp[i] I get (nil)

As others have mentioned, you are probably getting (nil) because fopen() is
failing (most likely because you are opening too many files). If you want to
know the specific reason for the failure, or just be notified when such a
failure occurs, try using:

for(i=0;i!=256;i++)
    if ((fp[i]=fopen(file_name[i],"r+")) <= 0)  /* some will probably     */
                                                /* complain about using   */
                                                /* <= 0 comparison        */
    {
        perror("Error opening file");  /* this will print:                */
                                       /* "Error opening file: REASON"    */

        /* put error handler here, or just exit program */
    }



More information about the Comp.lang.c mailing list