Append one file to another.

This is a discussion on Append one file to another. within the C Programming forums, part of the General Programming Boards category; Hello. I wonder if it is possible to append one file to another. Something like this: FILE *text_file FILE *aux_file; ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    38

    Append one file to another.

    Hello.

    I wonder if it is possible to append one file to another. Something like this:

    FILE *text_file
    FILE *aux_file;

    text_file = fopen(filename, "w+");
    .....
    aux_file = funct_return_file();
    .....

    Then I would like to append aux_file to text_file

    Thanks in advance for your suggestions.

  2. #2
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    if both files are just text files, which has no headers it maybe work, but if not you will have a corrupted new file
    Mac OS 10.6 Snow Leopard : Darwin

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    38
    Yes, they would be two simple text files.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    i don't think there is a appending function... not as far as i now.
    You can use fread and fwrite
    Mac OS 10.6 Snow Leopard : Darwin

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Use "a" or "a+" to open a file for append.
    http://www.cppreference.com/stdio/fopen.html

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    38
    So maybe if I use FILE *text_file as a global/extern variable, I can write to just one file from different functions instead of appending?

  7. #7
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by guillermoh View Post
    So maybe if I use FILE *text_file as a global/extern variable, I can write to just one file from different functions instead of appending?
    Better to pass it as a parameter to these functions...

    And still - you need to append to "append one file to another"
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  3. 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
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

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