473,657 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple file compression program

Dear all,

the following is the file compression program ,using elimination of
spaces, which I saw in a book

#include<stdio. h>
#include<stdlib .h>

int main(int argc,char * argv[])
{

FILE* fs,*ft;

fs = fopen(argv[1],"r");
if(fs == NULL)
{
printf("\n Cannot open the file %s",argv[1]);
exit(1);
}

ft = fopen(argv[2],"w");
if(fs == NULL)
{
printf("\n Cannot open the file %s",argv[2]);
exit(1);
}

while( (ch=fgetc(fs)) != EOF)
{

if(ch == 32)
{
if( (ch=fgetc(fs)) != EOF)
fputc(ch+127,ft );
}
else
fputc(ch,ft);

}

fclose(fs);
fclose(ft);

return EXIT_SUCCESS;
}

Now my questions are as as follows

1) Is there any other simpler method to compress text files, similar
to the above program(Other than standard algorithms like huffman,LZW)
Mar 26 '08 #1
3 9226
On Mar 26, 3:09 pm, sophia <sophia.ag...@g mail.comwrote:
if(ch == 32)
{
if( (ch=fgetc(fs)) != EOF)
fputc(ch+127,ft );
}
else
fputc(ch,ft);
What happens when the character represented by the value 32 is the
last character in the file? You are not writing any representation of
that character to your output file. You will not be able to recreate
your source file.
Now my questions are as as follows

1) Is there any other simpler method to compress text files, similar
to the above program(Other than standard algorithms like huffman,LZW)
yes. Not really a C issue however. First define what you mean by 'text
file', then devise a way of mapping the (smaller) domain of your text
file into the (larger) domain of an unsigned char. And don't forget to
open your destination file for binary access.
Mar 26 '08 #2

"sophia" <so**********@g mail.comwrote in message
1) Is there any other simpler method to compress text files, similar
to the above program(Other than standard algorithms like huffman,LZW)
squnch compression. It's a sliding dictionarty method that has seen
induistrial use because of its super-fast decompress. Look in the Basic
Algorithms pages of my website.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Mar 26 '08 #3
On Wed, 26 Mar 2008 13:09:35 -0700 (PDT), sophia
<so**********@g mail.comwrote:
>Dear all,

the following is the file compression program ,using elimination of
spaces, which I saw in a book
Was it listed as a bad example? Perhaps the book was intended as a
satire?
>
#include<stdio .h>
#include<stdli b.h>

int main(int argc,char * argv[])
{

FILE* fs,*ft;

fs = fopen(argv[1],"r");
How does the program know argv[1] is not NULL or for that matter that
it even exists?
if(fs == NULL)
{
printf("\n Cannot open the file %s",argv[1]);
exit(1);
}

ft = fopen(argv[2],"w");
if(fs == NULL)
{
printf("\n Cannot open the file %s",argv[2]);
exit(1);
}

while( (ch=fgetc(fs)) != EOF)
Where is ch declared?
>{

if(ch == 32)
32 is not the value of ' ' on my system.
{
if( (ch=fgetc(fs)) != EOF)
fputc(ch+127,ft );
On my system adding 127 to a printable character value will produce a
value that won't fit in a char. While this technically isn't overflow
since fputc takes an int, it will mess up the output file.

It appears to skip only one space. And it does so without regard to
whether the space is "significan t".
}
else
fputc(ch,ft);

}

fclose(fs);
fclose(ft);

return EXIT_SUCCESS;
}

Now my questions are as as follows

1) Is there any other simpler method to compress text files, similar
to the above program(Other than standard algorithms like huffman,LZW)

Remove del for email
Mar 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4073
by: Enrique | last post by:
hello all! i´m working with big size files, to maintain them, it would be better to compress the files. to recover a little part of the big file, how can i extract that little parte instead of the whole file that will bring a lot of time? Can i know the offset in a zip file?? i know the offset in the big one. Any idea will be welcome. Thanks.
8
8830
by: Dennis Hotson | last post by:
Hi, I'm trying to write a function that adds a file-like-object to a compressed tarfile... eg ".tar.gz" or ".tar.bz2" I've had a look at the tarfile module but the append mode doesn't support compressed tarfiles... :( Any thoughts on what I can do to get around this?
1
1959
by: Phil Price | last post by:
Hi there, I'm developing a shape recognition application for the tablet PC for a) fun b) university project. Currently I'm working on the learning stage using neural networks, and have to store a load of learning data (a 25 by 25 matrix) each shape group has a number of user drawn shapes, then the application will create variations of these shapes (by moving nodes and drawing lines into the matrix between nodes, after normalization). So...
20
8792
by: Chris LaJoie | last post by:
I'm looking for some kind of simple string compression code I can use. I'm not looking for SharpZipLib. Their implimentation spans several classes and is very complex. I'm just looking for something simple. A single class, preferrably. Does such a thing exist? Thanks, Chris
22
3972
by: petermichaux | last post by:
Hi, I'm curious about server load and download time if I use one big javascript file or break it into several smaller ones. Which is better? (Please think of this as the first time the scripts are downloaded so that browser caching is out of the equation.) Thanks, Peter
52
7505
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the file doesn't exist.Now tell me what should I do! Thanks
6
2029
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation- this is somewhat of a hobby for me. Many of my end users are computer phobic and get little support from their IT departments. It is a split database so the datafile gets put on the file server and the 3 different front ends get put on each local...
10
110207
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and it also integrates UPX (Ultimate Packer for eXecutables) into the build process, if you have it installed. It also claims functionality on linux, as a bonus (I didn't test this). I highly recommend the UPX options, and will cover how to get it...
59
3442
by: riva | last post by:
I am developing a compression program. Is there any way to write a data to file in the form of bits, like write bit 0 then bit 1 and then bit 1 and so on ....
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.