473,223 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

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 9201
On Mar 26, 3:09 pm, sophia <sophia.ag...@gmail.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**********@gmail.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**********@gmail.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<stdlib.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 "significant".
}
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
by: Enrique | last post by:
hello all! im 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...
8
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...
1
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...
20
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...
22
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...
52
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...
6
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-...
10
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...
59
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
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.