file closing

This is a discussion on file closing within the C Programming forums, part of the General Programming Boards category; I opened arbitrarily numbers of file opened I have the name of file. how should I close them all by ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    53

    file closing

    I opened arbitrarily numbers of file opened
    I have the name of file.
    how should I close them all by not store all the FILE* which I opened.
    Is there anyway to close a file by name?
    Last edited by p595285902; 03-23-2011 at 09:26 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    The only way to close a file is by using the pointer returned by fopen(). If you use fopen() but don't store the returned pointer anywhere then you're hosed. Why would you open a bunch of files without storing the pointer anyway? You can't read or write to a file without the pointer either.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by p595285902 View Post
    I opened arbitrarily numbers of file opened
    I have the name of file.
    how should I close them all by not store all the FILE* which I opened.
    Is there anyway to close a file by name?
    As my friend itsm86 says... you've made yourself something of a problem.

    The easy way is to keep an array of file pointers...
    Code:
    FILE *Files[100];
    You need the pointers --and the correct ones-- to read and write files and you absolutely need them to close the files.

    Also, keep in mind that many OSs and some compilers have a limit on the number of files they can open simultaneously...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Closing a binary file before it ends
    By cedrik23 in forum C Programming
    Replies: 8
    Last Post: 12-11-2007, 12:26 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21