在C中一次打开两个文件? [英] Open two files at one time in C?
问题描述
C可以在任何给定时间打开(并保持打开)两个文件吗?
所以,
文件* a,* b ;
a = fopen(argv [1]," r");
b = fopen(argv [2]," r");
?
Can C open (and keep open) two files at any given time?
so,
FILE *a, *b;
a = fopen(argv[1], "r");
b = fopen(argv[2], "r");
?
推荐答案
pa ****** @ gmail.com 写道:
C可以打开(并保持打开)两个文件在任何给定的时间?
所以,
文件* a,* b;
a = fopen(argv [1]," r");
b = fopen(argv [2]," r");
?
Can C open (and keep open) two files at any given time?
so,
FILE *a, *b;
a = fopen(argv[1], "r");
b = fopen(argv[2], "r");
?
我不知道它是在C标准中定义的,但是我还没有找到一个操作系统并不允许至少两个文件同时打开
。
I don''t know that it is defined in the C standard, however I''ve yet to
find an operating system that doesn''t allow at least two files to be
open concurrently.
是的,你可以。这就是为什么你有
FILE * a,* b,等等
你可以打开尽可能多的环境
pa******@gmail.com 写道:
Yes you can. This is why you have
FILE *a, *b, ect
you can open as many as the enviornment allows
pa******@gmail.com wrote:
C可以在任何给定时间打开(并保持打开)两个文件吗?
所以,
文件* a,* b ;
a = fopen(argv [1]," r");
b = fopen(argv [2]," r");
?
Can C open (and keep open) two files at any given time?
so,
FILE *a, *b;
a = fopen(argv[1], "r");
b = fopen(argv[2], "r");
?
pa******@gmail.com 写道:
C可以在任何给定时间打开(并保持打开)两个文件吗?
Can C open (and keep open) two files at any given time?
打开文件的数量是与平台相关的数量。
有些系统将此限制作为常量编译成OS内核,
其他人用环境变量定义它,其他人有硬和软
限制,例如,基于每个用户分配不同,或者
可以在系统范围内打开的文件总数与打开的每个进程相比。
stdio中文件描述符的一个非常常见的实现
库恰好使用8位无符号字符(8位),这限制了
范围的文件描述符,可以将其作为FILE *打开到0-255。
在我想到的特定系统上,描述符0,1和2分别为stdin,stdout和stderr保留
,留下253
fd',其中包括popen()和socket()以及accept()调用,以及
因此它是一个非常常见的真实世界脚本达到此限制;
特别是在网络应用程序中。我指的是64位版本的操作系统,允许65536个打开的文件。
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);
?
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.
这篇关于在C中一次打开两个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!