Can C open (and keep open) two files at any given time?
The number of open files is a platform-dependent quantity.
Some systems have this limit as a constant compiled into the OS kernel,
others define it with an environment variable, others have hard and soft
limits, allocated differently on a per-user basis, for instance, or a
total number of files that can be open system-wide versus open per-process.
One quite common implementation of the file descriptor in a stdio
library happens to use an 8-bit unsigned char (8 bits), which limits the
range of file descriptors which can be opened as FILE *'s to 0-255.
On the particular system I have in mind, descriptors 0,1, and 2 are
always reserved for stdin, stdout, and stderr respectively, leaving 253
fd's, which includes popen()'s and socket() and accept() calls also, and
so it is a very common real-world scenario that this limit is reached;
particularly in a network application. The 64-bit version of the OS I
am referring to, allows 65536 open files.
so,
FILE *a, *b;
a = fopen(argv[1], "r");
b = fopen(argv[2], "r");
?
I don't know of a system that has files at all, that doesn't allow you
to open at least two descriptors.