Thread: Extracting archive

  1. #1
    Registered User
    Join Date
    Oct 2009

    Extracting archive

    I know only basic file handling and was wondering if anyone would help me out with the following code :

    1. Extract an archive using C
    2. Extract an archive with password using C

  2. #2
    Registered User
    Join Date
    Sep 2006
    Welcome to the forum!

    To get help, you need to show your work on the problem. Our help is rather limited to C, not decrypting an encoded archive or cracking a password.

    I'm not saying you're trying to do that, I'm just being up front about this.

    We help folks with C, all the time.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Well, i'm new to C and i know the basic file-handling functions like fopen, fprintf etc.
    I have implemented these functions only in text files and database programs using


    fprintf(fptr1,"Record No.\tName\t\tRoll No.\tAggregate Marks");

    ......... and so on

    i was wondering if a program could be written in C to extract an archive(Zip,RAR)

    And you've misunderstood me on the second count .. i meant that i would have the password and i would just be extracting a file using c instead of manually, so i think that eliminates the decrypting part.

    Simply put ... all i want to do is extract an archive of which i already have the password ...using C, assuming of course that the archive is in the same folder as the executable file after compilation
    Last edited by cerebrassassin; 10-25-2009 at 08:57 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Oh yes, of course you can extract zip and rar files with C . In all likelihood, both were written in C in the first place.

    However, the easier way to do this, is to use a de-compression program that runs from the command line, and handles the format you want (whether zip or rar or both).

    Now your C program can just use the system command to call that program, let it do it's work, and then return to work, having just paused, while the de-compression program was working.

    Imagine I have a program called "unzip.exe", which was a command line program (no gui needed), and took two parameters:

    1) the name of the file, and
    2) the password needed, if any.

    Now my C code for it could look something like this:

    system("unzip filename password");

    filename doens't have to be a single filename, it can change, and so can the password, by changing the above command slightly:

    system("QuestSolver.exe < "filename) //note the string quotes ending before filename

    In this case, I was calling another program called Questsolver.exe and giving it the file I had #defined earlier, which was in another drive and directory.

    I believe you can call send any filename like this, using a char array for filename, but haven't tried it yet.

    Where it gets sticky is when the program has to run from a GUI, and you have to click on certain icons, or check certain boxes - all that mouse and keyboard interaction is what you want to avoid.

    I'd put off coding up the actual de-compression program yourself, until you have quite a bit of experience with C programming and of course, have a good understanding of the algorithm that should be used.

  5. #5
    Registered User
    Join Date
    Oct 2009


    Thanx a ton dude....
    I got hold of this freeware called 'UNRAR' and as you advised, I used the system's command prompt to extract the files and it works like a charm.
    Thnx again ... this forum rox... i'm here to stay!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting info from a packet trace file
    By Ho ming in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 11:54 AM
  2. C++ snippet Archive
    By squako in forum C++ Programming
    Replies: 16
    Last Post: 12-17-2006, 12:12 PM
  3. Testers wanted - archiving tool.
    By cboard_member in forum Game Programming
    Replies: 25
    Last Post: 08-31-2006, 06:12 AM
  4. archive format
    By Nor in forum A Brief History of
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. extracting words from an array of words
    By axon in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 11:21 PM