Thread: Can't copy a file. Help

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

    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];

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


    return 0;

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

  2. #2
    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, 07: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, 03:39 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM