Extracting archive

This is a discussion on Extracting archive within the C Programming forums, part of the General Programming Boards category; I know only basic file handling and was wondering if anyone would help me out with the following code : ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    6

    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
    Posts
    8,868
    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
    Posts
    6
    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

    fptr1=fopen("data.txt","r+");
    if(fptr1==NULL)
    {
    printf("ERROR");
    exit(1);
    }

    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 09:57 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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
    Posts
    6

    Cool

    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, 12:54 PM
  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, 07:12 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08: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

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