You are here:

C/How read text file inside Archive files by 'C '

Advertisement


Question
I have tried finding the solution for the problem on google but unable to find a solution that supports both the Archive formats i.e Rar/Zip.I tried with 7zip [7zip][1] but it has functions thar compress/decompress or extracts the contents of Archive files , While searching for the solution I found minizip supports both the formats Rar/Zip with [minizip][2]

I tried to open the text file inside Archive,but it's unable to open it.

Possibly I am looking forward to  [zlib][3] as a possible approach but it is a dll,and I dont know about how its functions work and do they perform the task of reading from a text file inside the Archive.

So, please give guidance as how to move ahead in this task, i am not sure with zlib.

**Making the requirement clear again**

I just want to read the content of text files inside archive (rar/zip) For e.g I have Archive C:\Test.rar and Test.rar contains filesample.txt , so my requirement is to read the content of filesample.txt directly ,I dont want to extract the files.


 [1]: http://sourceforge.net/projects/sevenzip/files/LZMA%20SDK/lzma920.tar.bz2/downlo
 [2]:http://code.google.com/p/miniz/downloads/detail?name=miniz_v115_r4.7z
 [3]: http://www.winimage.com/zLibDll/minizip.html//%22%22

Answer
Hi Dhawal,

Based on your requirements libarchive looks like a good choice. libarchive is an opensource library that supports both rar and zip. The libarchive github page has good documentation with examples: https://github.com/libarchive/libarchive/wiki/Examples#A_Complete_Extractor

-Tony

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.