copy file

This is a discussion on copy file within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I intend to copy file, i'm using function fgets to get each record and then put it into the new ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    copy file

    I intend to copy file, i'm using function fgets to get each record and then put it into the new file....but......it doesn't work the destination file contains nothing,

    handle=fopen("karyawan.dat","w"); // the destination file

    temporer=fopen("temp.$$$","r"); // the source file

    while(fgets(kodec,53,temporer)!=NULL)

    {fprintf(handle,"%s",kodec);

    }

    by the way......it seems to work...i mean i could exit the program..but when i check the file it's nothing......

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,825
    Did you check all those functions for error returns?

    And how is kodec declared.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Unregistered
    Guest
    i have checked it.....they work...i declared kodec as:
    char kodec[54];
    please help me.....it really confuses me.....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,825
    Should work if its a text file you're trying to copy.
    But if it's a binary file (like a .exe), then it wont work.

    Oh, and the opposite of fgets is fputs, not fprintf
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    11
    Man.....i'm so sorry for wasting your time thinking about my stupid code......i have found the reason why it didn't work...I forgot to close the file (fclose(temporer) and fclose(handle)).....btw.....thank's for your kindness.....I'll be more carefull in the future

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