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

Blair P. Houghton bhoughto at cmdnfs.intel.com
Wed Nov 28 03:15:19 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)

How big is `i'?  If it's over 63, you're likely to
have a problem.  On older machines, the maximum is 19
(i.e., only 20 file descriptors allowed).

1.  Find out what standard header file on your system
defines the number of file descriptors you may use.
(Usually it will be defined in stdio.h).

2.  Find out what the macro is called (Under Ultrix 3.1 it's _NFILE).

3.  Include the header.

4.  Replace `256' with the macro everywhere.

5.  Avoid trying to access beyond the end of the array
(on some systems it's a core-dumping segmentation violation).

There's nothing wrong with using an array of file pointers
instead of unarrayed file pointers.

				--Blair
				  "Currently working on an in-circuit
				   emulator for the Milton-Bradley
				   game, 'Operation.'  Bzzzt! :-)"



More information about the Comp.lang.c mailing list