Thread: File Cutter / Sticker

  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    File Cutter / Sticker

    Hello,

    I'm writing a short program that'll open a large file and cut it to smaller files of a defined size, and another program that'll do the inverse - stick the small files together to make one big file back.

    For a reason I can't quite figure out, I'm getting an ifstream error when I try to run the code. Here's the important part :

    Code:
        fin.open("fileA.part", ios::binary);
        fout.open(FILENAME, ios::binary);
        
        char a;
        int count(0);
        
        while(count != PARTS+1)
        {
            if(fin.eof())
            {
                fin.close();
                temp = filename;
                files += 1;
                temp += files;
                temp += ending;
                fin.open(temp.c_str(), ios::binary);
                if(!fin) { cout << temp; Sleep(2000); }
            }
            count++;
            while(fin.get(a)) fout << a;        
        }
    I know the code is a mess :P Basically :
    Open the first file, and open the receiving output file. Until you reach the end of that file, keep transferring data. When you reach EOF, close the input file, open a new one (temp, filename and ending are strings (string.h)). If you can't open it, give me the name of the file you can't open. If you CAN open it, just increase the counter telling you what part you're on and keep transferring data. Global WHILE - while your counter doesn't exceed the total number of parts, keep opening part files.


    The trouble comes in that ifstream error statement - if you can't open the file, write out the name of that file. It gives me the name of the file, showing that fin.open() failed, but the filename is correct and the file exists in the right directory.

    Any ideas ?

    Thanks very much,
    Quent

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Closing a stream doesn't clear any error states. In this case, the eofbit is still set. You need to say "fin.clear()" before trying to open the file.
    My best code is written with the delete key.

  3. #3
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks very much Prelude, I was looking for an error statement or .clean() or .flush(), but didn't remember .clear() All works now.

    Thanks again,
    Quentin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM