Can't copy a file. Help

This is a discussion on Can't copy a file. Help within the C++ Programming forums, part of the General Programming Boards category; Hi there. Few days ago I desided to create small program that would copy any file. But I met some ...

  1. #1
    Registered User alex6852's Avatar
    Join Date
    Sep 2001
    Posts
    43

    Exclamation Can't copy a file. Help

    Hi there. Few days ago I desided to create small program that would copy any file. But I met some realy serios problem: if file I want to copy is not a txt-file(*.wav, *.bmp, *.doc etc.) my program copies few symbols and closing file. Here's simplefied version of my program:

    #include <fstream.h>

    int main(int argnum, char* argu[])
    {
    if (argnum == 1)
    {
    cout << " File Copier V1.0 " << endl;
    cout <<'\n'<< " Usage: filecpy.exe file1 file2 " << endl;
    return 1;
    };

    ifstream infile (argu[1]);
    ofstream fileout (argu[2],ios::app);

    if( ( !infile ) || ( !fileout) )
    {
    cout << "\n ERROR! Enable to open/create file ! \n";
    return 1;
    };

    char ch[60];
    infile.unsetf(ios::skipws);

    while (!infile.eof())
    {
    infile >>ch;
    fileout << ch;
    };

    infile.close();
    fileout.close();

    return 0;
    }

    Please help me solve that problem, it realy holding be back. Thank You.
    C++ rulez!!!

  2. #2
    SOAK
    Guest
    LPSTR Progname; //obviously you need to input a value to Progname
    FILE *OriginalFile = fopen(Progname, "rb");
    FILE *CopiedFile = fopen(Copyofprog, "wb");
    int gk;
    while ((gk = fgetc(OriginalFile)) != EOF);
    fputc(gk, CopiedFile);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

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