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");
? 14 18405 pa******@gmail.com wrote:
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");
?
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.
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:
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 wrote:
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. pa******@gmail.com wrote:
Can C open (and keep open) two files at any given time?
This is implementation defined and for a particular instance it is
given by the macro FOPEN_MAX in stdio.h. It includes stdin, stdout and
stderr.
On 29 Nov 2006 20:52:21 -0800, "santosh" <sa*********@gmail.com>
wrote:
>pa******@gmail.com wrote:
>Can C open (and keep open) two files at any given time?
This is implementation defined and for a particular instance it is given by the macro FOPEN_MAX in stdio.h. It includes stdin, stdout and stderr.
And both C90 and C99 have this to say about FOPEN_MAX:
"The value of FOPEN_MAX shall be at least eight, including the three
standard text streams."
This means that the OP can indeed open (and keep open) two files at
any given time on any conforming C implementation.
--
jay
jaysome <ja*****@spamcop.netwrote:
On 29 Nov 2006 20:52:21 -0800, "santosh" <sa*********@gmail.com>
wrote:
pa******@gmail.com wrote:
Can C open (and keep open) two files at any given time?
This is implementation defined and for a particular instance it is
given by the macro FOPEN_MAX in stdio.h. It includes stdin, stdout and
stderr.
And both C90 and C99 have this to say about FOPEN_MAX:
"The value of FOPEN_MAX shall be at least eight, including the three
standard text streams."
This means that the OP can indeed open (and keep open) two files at
any given time on any conforming C implementation.
Wrong. It means that _the implementation_ shall not stop you from
opening less than that. If the OS stops the implementation from opening
that many files for you, there's nothing to be done about it, at least
not within ISO C.
(What, for example, if strict sandboxing and rights restrictions mean
that there only is a single file which your program can even see, let
alone open?)
Richard rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
jaysome <ja*****@spamcop.netwrote:
>On 29 Nov 2006 20:52:21 -0800, "santosh" <sa*********@gmail.com> wrote:
>pa******@gmail.com wrote: Can C open (and keep open) two files at any given time?
This is implementation defined and for a particular instance it is given by the macro FOPEN_MAX in stdio.h. It includes stdin, stdout and stderr.
And both C90 and C99 have this to say about FOPEN_MAX:
"The value of FOPEN_MAX shall be at least eight, including the three standard text streams."
This means that the OP can indeed open (and keep open) two files at any given time on any conforming C implementation.
Wrong. It means that _the implementation_ shall not stop you from
opening less than that. If the OS stops the implementation from opening
that many files for you, there's nothing to be done about it, at least
not within ISO C.
The OS is part of the implementation. The implementation guarantees
that at least FOPEN_MAX files can be open simultaneously. If this
guarantee is not met, the implementation is non-conforming (though it
may not be the fault of, say, the compiler or the C runtime library).
(What, for example, if strict sandboxing and rights restrictions mean
that there only is a single file which your program can even see, let
alone open?)
What if the OS doesn't allow objects larger than 20,000 bytes? Then
the implementation is non-conforming.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Keith Thompson <ks***@mib.orgwrote: rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
jaysome <ja*****@spamcop.netwrote:
On 29 Nov 2006 20:52:21 -0800, "santosh" <sa*********@gmail.com>
wrote:
pa******@gmail.com wrote:
Can C open (and keep open) two files at any given time?
This is implementation defined and for a particular instance it is
given by the macro FOPEN_MAX in stdio.h. It includes stdin, stdout and
stderr.
And both C90 and C99 have this to say about FOPEN_MAX:
"The value of FOPEN_MAX shall be at least eight, including the three
standard text streams."
This means that the OP can indeed open (and keep open) two files at
any given time on any conforming C implementation.
Wrong. It means that _the implementation_ shall not stop you from
opening less than that.
(What, for example, if strict sandboxing and rights restrictions mean
that there only is a single file which your program can even see, let
alone open?)
What if the OS doesn't allow objects larger than 20,000 bytes? Then
the implementation is non-conforming.
That would mean that an implementation can go from conforming to
non-conforming just because someone, possibly someone using a completely
different program, deletes readable file #8. In fact, an implementation
can go from non-conforming to conforming just by creating 8 files where
there were none; and go back to conforming if the program itself calls
remove() on one of those files. That cannot possibly be the intent.
Richard pa******@gmail.com wrote:
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");
The question has been answered very well else-thread. However, did you
even try it?
Also, although this was mentioned in another reply, please consider that
most implementations give you three file descriptors upon program start.
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote: rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
(What, for example, if strict sandboxing and rights restrictions mean
that there only is a single file which your program can even see, let
alone open?)
That would mean that an implementation can go from conforming to
non-conforming just because someone, possibly someone using a completely
different program, deletes readable file #8. In fact, an implementation
can go from non-conforming to conforming just by creating 8 files where
there were none; and go back to conforming if the program itself calls
remove() on one of those files. That cannot possibly be the intent.
It seems to me that FOPEN_MAX is intended to guarantee that a call to
fopen() will not fail solely because of the number of files that are
already open until FOPEN_MAX files are opened. So as far as the OP is
concerned, it's reasonable to say that "If the implementation allows
you to open file A, and if the implementation allows you to open file
B, then the implementation must allow you to have file A and file B
open simultaneously." All the other details of what and how many files
a program may actually open are implementation-defined, are they not?
--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Clever Monkey wrote:
pa******@gmail.com wrote:
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");
The question has been answered very well else-thread. However, did you
even try it?
Also, although this was mentioned in another reply, please consider that
most implementations give you three file descriptors upon program start.
ITYM pointers to type FILE. As you know, file descriptors are an UNIX
specific lower level mechanism, and nothing to do with standard C.
Clever Monkey <cl**************@hotmail.com.invalidwrote:
Also, although this was mentioned in another reply, please consider that
most implementations give you three file descriptors upon program start.
If you're talking about stdin, stdout, and stderr, then all hosted
implementations must provide them, yes?
--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome. sg*******@gmail.com wrote:
Yes you can. This is why you have
FILE *a, *b, ect
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or:
<http://www.caliburn.nl/topposting.html>
Christopher Benson-Manica <at***@norge.freeshell.orgwrites:
Richard Bos <rl*@hoekstra-uitgeverij.nlwrote:
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
(What, for example, if strict sandboxing and rights restrictions mean
that there only is a single file which your program can even see, let
alone open?)
>That would mean that an implementation can go from conforming to non-conforming just because someone, possibly someone using a completely different program, deletes readable file #8. In fact, an implementation can go from non-conforming to conforming just by creating 8 files where there were none; and go back to conforming if the program itself calls remove() on one of those files. That cannot possibly be the intent.
It seems to me that FOPEN_MAX is intended to guarantee that a call to
fopen() will not fail solely because of the number of files that are
already open until FOPEN_MAX files are opened. So as far as the OP is
concerned, it's reasonable to say that "If the implementation allows
you to open file A, and if the implementation allows you to open file
B, then the implementation must allow you to have file A and file B
open simultaneously." All the other details of what and how many files
a program may actually open are implementation-defined, are they not?
That makes excellent sense. Whether it follows from the wording of
the standard is another question, but one in which I'm afraid I've
suddenly lost interest, so I'll just go with your explanation.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yanivmad |
last post by:
hi
I like to ask if there any option to control the html files?!?
I have some HTML files at my web site that use
one "Help.htm" file for all the pages {I use the
"window.open(.... " option at...
|
by: yanivmad |
last post by:
hi
I like to ask if there any option to control the html files?!?
I have some HTML files at my web site that use
one "Help.htm" file for all the pages {I use the
"window.open(.... " option at...
|
by: RSB |
last post by:
Hi Every one,
I am currently using Visual Studio .Net and trying to open a project from
SourceSafe and once i open the project for the first time i get the
following error/warning...
"The...
|
by: J e r |
last post by:
I'm a novice using VB .NET . I'm trying to use 2 files to read a line write
the line and get the run time error
"..exception of type 'System.IO.IOException.....additional information:
File...
|
by: Shimon Sim |
last post by:
Hi
1) Is it possible to force browser to open image in default windows
application? That is what specifies in Folder Options for jpg extension.
2) Also if the 1) is possible is it possible to...
|
by: john |
last post by:
How safe is it to back up a single user mdb when it is opened. No tables are
opened at the time of the backup. The only object that is open is the form
from which the backup code is being run....
|
by: jonathandrott |
last post by:
sorry newbie question probably. i'm trying to open an specific folder.
open each file with in the folder individually and process each one.
all the processing code has been written. i'm looking...
|
by: AMD |
last post by:
Hello,
I need to split a very big file (10 gigabytes) into several thousand
smaller files according to a hash algorithm, I do this one line at a
time. The problem I have is that opening a file...
|
by: hharry |
last post by:
Hello All,
Does anyone know of a method to automatically detect if a file is
corrupted ?
Due to a failed backup process a number of files were corrupted. The
files are mostly .xls, .doc, .pdf....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |