storing files on buffer and copy paste to another file :S

This is a discussion on storing files on buffer and copy paste to another file :S within the C Programming forums, part of the General Programming Boards category; So i'm making a file archive utility and apparently we are supposed to be storing the files on the buffer, ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    2

    storing files on buffer and copy paste to another file :S

    So i'm making a file archive utility and apparently we are supposed to be storing the files on the buffer, using the buffer as a pointer, then copying this to another file as the compression process.
    i have absolutely no idea where to start for this section of my project.
    can anyone lead me in the right direction.
    i dont even know if im talking complete trash right now.
    sorry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    A really stupid archiver
    Code:
    $ cat file1.txt 
    this is file1
    $ cat file2.txt 
    this is file2
    $ cat file1.txt file2.txt > archive.txt
    $ cat archive.txt 
    this is file1
    this is file2
    Before you start worrying about compression, focus on just joining two files together to produce one file. Now cat does this just fine, but you may notice it's rather hard to get back to the original files.

    So the first thing to do is add some information that allows you to also store the filename(s) and lengths.
    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
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, connor9!

    It makes sense to work through the file's data, one "bucket"'s worth at a time. How many file(s) or parts thereof you can store on the buffer before writing out, depends on the system, of course.

    First thing is to get the user input for this. Maybe a menu, asking what file(s) they want archived, or will it be just a "archive everything that isn't already archived", kind of a program? The C Tutorial tab at the top of the C forum page, shows how you can do a lot of things - like reading files on the drive, if you need that capability.

    Second, what about a compression utility function or library to compress these archived files? Mandatory? Optional? Not needed?

    Can't really lead you in the right direction, because I wasn't in the classroom when the assignment was discussed. That is all up to you to decide what you should be doing in this project.

    Once we have some code from you, we can discuss any problems you're having in the C part of it. Before that, we can't do much except cheer from the sidelines, perhaps.

    Googling archiving file programs, should give you some ideas perhaps.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    "buffer as pointer" sounds to me like you should use malloc to allocate a chunk of memory and assign its address to a pointer. Then read a file into this buffer. Perhaps pre-read the file or use some file system call to determine the file's size before proceeding.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    2
    Sorry, maybe I should've explained a little more.
    I've made a utility to merge then copy files to different directories at the moment. That's all I've done so far.
    So now im trying to add in compression of the merged file so that when i move/copy it to a new directory it can be de-compressed.
    Our lecturer and said he wants to be incredibly mean and give us a miserable christmas (harsh i know.. but thats just his personality) so he hasn't given us much information.
    I've tried looking at some compressing methods but with limited knowledge it seems that librarys are to be #included that won't be installed on the computer at university (where this utility is going to be ran)
    "malloc" what nonoob mentioned sounds familiar
    and also "cat" what salem mentioned also does too
    so i'll research these a bit more so i can give you guys a better understanding of what im trying to achieve.

    would just like to say, thanks for the help you've already given and the great replies!

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I like the implications of words like "concatenate" or "stack" files, but "merge" sounds real iffy - like merge sort or some interleaving of the data between files is going on.

    That's not the case, surely.

    Stick with standard C functions, and your own code. You'll be saving room for and making an index to where each file begins, in the archive, and writing it out as a header to the first part of the archive? Or maybe using a sentinel value and just name the file, then have the contents, until the sentinel value is found, and repeat as needed for all the files? This last approach sounds robust and simple (but I've never coded up an archive program before).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin + copy paste
    By Ducky in forum C++ Programming
    Replies: 5
    Last Post: 12-17-2012, 06:33 AM
  2. Custom Copy/Paste
    By C_ntua in forum Windows Programming
    Replies: 5
    Last Post: 06-16-2010, 01:15 PM
  3. simulating Explorer Cut/Copy/Paste of files
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 03-26-2008, 12:34 PM
  4. copy paste from another app
    By bonkey in forum Windows Programming
    Replies: 1
    Last Post: 09-08-2003, 08:03 AM

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