473,569 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

huffman encoder

Hi all,

this is the program which I saw in my colleagues book. the program was
run on turbo C++ 3.0 compiler

/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_

#include <io.h>
#include <conio.h>
#include<stdio. h>

typedef struct node
{
unsigned char c;
unsigned long int freq;
struct node *up,*left,*righ t;
}sn;

typedef struct ftable
{
unsigned long int freq;
}sft;

/*global variables*/
int buf[50],bc;
sft ft;
sn leaf[256];
sn *a,*t[256];

/*function prototypes*/

int initialize(char *);
/* operation: initialization function
post conditions: initializes all leaves to null values,barring the
character whose
frequency they point to.sets frequency values of the leaves
*/
int sortnode(int);
/* operation: sorting function
post conditions: sorts the pointer nodes in the decreasing order of
frequency*/

int getnodecount();
/* operation: get count of nodes with non zero frequency
post conditions: */

int createtree();
/* operation: creating the tree
post conditions: creats a non optimal huffman tree
to generate prefix codes
*/

int comparenode(sn* ,sn*);
/* operation: node comparison
post conditions: returns 0 if both pointers point to same data
else returns -1
*/

void addtobuffer(int );
/* operation: initializing the bit buffer
post conditions: holds prefix codes for each leave nodes
*/

void refreshbuffer(F ILE *);
/* operation: writing the coded prefix character
post conditions:
*/
/*void freetree(sn*);*/
char* getfilename(cha r *);
/* operation: obtaining the file name
post conditions: splits the file path to obtain the file name
*/

unsigned char getoddchar();
/* operation: same as that of refreshbuffer
pre conditions: bit buffer with less than 8 bits
*/

#endif

/*end of header file*/

/*
static version of huffman coding.
it is by no means optimal
compresses files above 3.25 kb
upper limit has not been determined upto 50K OK
usage of global variables
imperfect coding
usage of non standard functions lack of garbage collector leaves much
to be desired it might eat your memory if u are running this program on
old dos machines
*/

#include"huff.h "
int main(void)
{
FILE *fp,*fq;
int ch,i;
char fname[100],efile[100];
unsigned long int fsize,efsize;

clrscr(); /*non standard fn*/
printf("\nHuffm an encoder");
printf("\nEnter the name of the input file(to be compressed):");
fgets(fname,100 ,stdin);
fname[strlen(fname)-1]=0;

printf("\nEnter the output filename(compre ssed file):");
fgets(efile,100 ,stdin);
efile[strlen(efile)-1]=0;

if(initialize(f name)==-1)
{
printf("\nError Could not open input file..");
return -1;
}
printf("\nIniti alization over.\nPreparin g to compress...");
if(createtree() ==-1)
{
printf("\nMemor y allocation error..");
return -1;
}
fq=fopen(efile, "wb");
if(!fq)
{
printf("\nError Could not open output file..");
fclose(fq);
return -1;
}
fp=fopen(fname, "rb");
if(!fp)
{
printf("\nError Could not open input file...");
fclose(fp);
return -1;
}
fsize=filelengt h(fileno(fp)); /*non std fn*/
/****To write the decoding table */
for(i=0;i<256;i ++)
{
ft.freq=leaf[i].freq;
fwrite(&ft.freq ,sizeof(struct ftable),1,fq);
}
/*To write the character that denotes the size of filenamelength*/
fputc(strlen(ge tfilename(fname ))+1,fq);
/*To write the filename*/
fwrite(getfilen ame(fname),strl en(getfilename( fname))+1,1,fq) ;
/***Completed writing of decoding table*****/
printf("\nCompr essing...");
while(ch=fgetc( fp),ch!=EOF)
{
addtobuffer(ch) ;
refreshbuffer(f q);
}
fputc(getoddcha r(),fq);
fputc(bc,fq);
fclose(fq);
printf("\nCompr ession complete.");
/*****For display of compression summary****/
fp=fopen(efile, "rb");
if(!fp)
{
printf("\nCould not open output file for analysis");
printf("\nCompr ession summary cannot be displayed");
return -1;
}
efsize=fileleng th(fileno(fp)); fclose(fp);
printf("\n\nCom pression summary\n");
printf("\nInput filesize :%lu bytes",fsize);
printf("\nOutpu t filesize:%lu",e fsize);
printf("\nCompr essed to %Lf%% of original size",((long
double)efsize*1 00/fsize));
return 0;
}
int sortnode(int z)/*sorts upto t[z] and not t[z-1]*/
{
int j,k;
sn* b;

for(k=0;k<=z;k+ +)
for(j=(k+1);j<= z;j++)
{
if((t[k]->freq)<(t[j]->freq))
{
b = t[k];
t[k] = t[j];
t[j] = b;
}
}
return 0;
}

char *getfilename(ch ar *filepath)
{
char drive[4],dir[67],file[15],ext[5];
fnsplit(filepat h,drive,dir,fil e,ext); //non standard fn
strcat(file,ext );
return file;
}
unsigned char getoddchar()
{
int i;
for(i=bc;i<8;i+ +)
{ buf[i]=0;}
return
((1*buf[7])+(2*buf[6])+(4*buf[5])+(8*buf[4])+(16*buf[3])+(32*buf[2])+(64*buf[1])+(128*buf[0]));
}

void refreshbuffer(F ILE *p)
{
int i;
unsigned char q;
while(bc>=8)
{

q=(1*buf[7])+(2*buf[6])+(4*buf[5])+(8*buf[4])+(16*buf[3])+(32*buf[2])+(64*buf[1])+(128*buf[0]);
if(fputc(q,p)!= (unsigned)q || q<0 || q>255)printf("\ nError");
for(i=8;i<bc;i+ +)
{buf[i-8]=buf[i];}
bc-=8;
}
}

void addtobuffer(int r)
{
int i,buftv[15];
int bct = -1,buft[15];

if(r>255 || r<0)
{
printf("\nValue error...");
getch();
}
a = &leaf[r];

while((a->up)!=NULL)
{
/* temp = a;*/
if(comparenode( (a->up->left),a)==0)
{buft[++bct]=0;}
else if(comparenode( (a->up->right),a)==0 )
{ buft[++bct]=1;}
else
{printf("\nPare nt Error"); /*For debugging*/}

a=a->up;
}

for(i=0;i<=bct; i++)
{ buftv[bct-i]=buft[i];}

for(i=0;i<=bct; i++)
{buf[bc+i]=buftv[i];}

bc += bct+1;
return;
}
int createtree()
{
int i;
sortnode(255);
for(i=getnodeco unt();i>0;i--)
{
sortnode(i);
a = NULL;
a = (sn *)malloc(sizeof (sn));

if(!a)
{
printf("\nMemor y allocation error...");
printf("\npress any key to continue...");
getch();
return -1; /*Memory allocation error*/
}
/*Assingning values*/
a->freq = (t[i]->freq)+(t[i-1]->freq);
a->right = t[i];
a->left = t[i-1];
a->up = NULL;
a->c = '\0';
t[i]->up = a;
t[i-1]->up = a;
t[i-1]=a;
}
return 0;
}
int initialize(char *filename)
{
int i,j;
FILE *fp;
for(i=0;i<256;i ++)
{
leaf[i].c = i;
leaf[i].freq = 0;
leaf[i].up = NULL;
leaf[i].left = NULL;
leaf[i].right = NULL;
}

fp=fopen(filena me,"rb");
if(!fp)
{ return -1; /*Could not open file */}

while(j=fgetc(f p),j!=EOF)
{
leaf[j].freq++;
if(j<0 || j>255)
{
printf("\nError ..."); //should add a exit fn here
getch();
}
}
fclose(fp);
for(i=0;i<256;i ++)
{
t[i]=&leaf[i];
if((t[i]->up)!=NULL)
{
printf("\nError ..");
getch();
}
}
bc=0;
return 0;
}

int getnodecount()
{
int i,h=0;
for(i=0;i<256;i ++)
{
if(leaf[i].freq==0)
h++;
}
return (255-h);
}

int comparenode(sn *a,sn *b)
{
if(a->c==b->c && a->freq==b->freq && a->up==b->up &&a->left==b->left
&& a->right==b->right)
return 0;
return -1;
}

/* void freetree(sn* hd)
{
if(!hd)
return;
freetree(hd -> left);
freetree(hd -> right);
free(hd);
}*/

now my questions are
1) how can the function freetree be implemented properly.
2) can anybody explain refreshbuffer funcion
i mean refresh buffer function writes the encoded bit pattern
using
fputc function.

the function of fputc function is as follows
int fputc(int ch, FILE *stream);

Writes a character (an unsigned char) specified by the argument ch
to the specified stream and advances the position indicator for the
stream.On success the character is returned. If an error occurs,
the error indicator for the stream is set and EOF is returned.

now my question is how compression is achieved,if we are writing ints

3) what exactly is the purpose served by these two statements in this
program???

fputc(getoddcha r(),fq);
fputc(bc,fq);

Dec 21 '05 #1
15 3668
In article <11************ **********@g49g 2000cwa.googleg roups.com>,
<aa*****@gmail. com> wrote:
this is the program which I saw in my colleagues book. the program was
run on turbo C++ 3.0 compiler /*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_ #include <io.h>
#include <conio.h>
That's a DOS/ Windows program, not standard C, so for bug analysis
you should be visiting a dos/windows programming newsgroup .

2) can anybody explain refreshbuffer funcion
i mean refresh buffer function writes the encoded bit pattern
using
fputc function. the function of fputc function is as follows int fputc(int ch, FILE *stream); now my question is how compression is achieved,if we are writing ints


That's an algorithm question, rather than a question about C.

Let me give a short example:

Suppose you have the input "abcdefghijXYZa bcdefghijPQR".
This could be written out as,
1 char with the high bit set to indicate an "escape" code,
and with the second-highest bit clear to indicate that this is
an escape of type "literal string",
and with the lower bits set to decimal 9 to indicate that
the literal string that follows is of length 10 (you never
have length 0 so don't waste a count)
10 characters that are abcdefghij
3 characters that are XYZ (high bit must be clear on each)
1 char with high bit set to indicate escape, second highest set
to indicate "back reference", and the lower bits set to 0 to indicate
that the reference is to the escaped string that occured most recently
3 characters that are PQR (high bit must be clear on each)

The total length of this representation is 1+10+3+1+3 = 18
whereas the original string took 26 characters.

Does this make it clearer as to how sometimes writing out binary
data can result in compression? The output binary can be interpreted
to -mean- something, and although the overhead required to encode
the data the -first- time might be larger than the original data,
if that bit of data repeats a number of time, if the encoding of
the reference is short and the data occurs many times, you use the
short representation each time, and it doesn't take long before the
overhead of the original encoding is more than made up for.

Anyhow, I suggest that rather than persuing this particular program,
that you read the comp.compressio n FAQ.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Dec 21 '05 #2
aa*****@gmail.c om wrote 392 lines, most of which is snipped:
Hi all,

this is the program which I saw in my colleagues book.
Please burn that book.
the program was
run on turbo C++ 3.0 compiler

/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_
The above illustrates a very bad idea, using identifiers that begin with
an underscore. Beginning identifiers with an underscore followed by an
uppercase letter is even worse. Avoid such things unless you *know*
when such things do not invade the namespace reserved to the
implementation. "HUFF_H" would have done as well.
#include <io.h>
There is no header <io.h> in standard C.
#include <conio.h>
There is no header <conio.h> in standard C.

[...]
Your code also exits in a number of places returning non-standard values
(not 0, EXIT_SUCCESS, or EXIT_FAILURE).

In addition, you return addresses of local variables, omit the inclusion
of <string.h> and <stdlib.h>, omit fflushing of stdout where needed
after a prompt not terminated with '\n', write 0 where you imagine the
'\n' to be in buffers filled by fgets, and use a number of
non-standard functions: clrscr(), filelength(), fileno(), fnsplit(),
getch(). God knows what other garbage is to be found in this horror.

Using a magic number (100) instead of FILENAME_MAX is a bad idea.
now my questions are
1) how can the function freetree be implemented properly.


Worry about the fact that the program is written by a 3rd grader who has
never learned C rather than trying to fix a pile of crap.
Dec 21 '05 #3
Martin Ambuhl <ma*****@earthl ink.net> wrote:
Please burn that book.
Isn't that a bit strong? We have no idea what the purported topic of
the book was or whether OP accurately transcribed what he found there,
or indeed whether there are errata that deal with the issues you
highlighted.
Worry about the fact that the program is written by a 3rd grader who has
never learned C rather than trying to fix a pile of crap.


I think the quality of the code suggests that it was not, in fact,
copied verbatim from any text, even a Schildt text.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 21 '05 #4
Martin ambuhl wrote
/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_
The above illustrates a very bad idea, using identifiers that begin
with
an underscore. Beginning identifiers with an underscore followed by an
uppercase letter is even worse. Avoid such things unless you *know*
when such things do not invade the namespace reserved to the
implementation. "HUFF_H" would have done as well.
Reply::

the following is the explanation given in the text book
C primer plus 3rd edition by stephen prata page no: 579

#ifndef directive is commonly used to prevent multiple inclusions of
a file.
that is a header file can be set up in the following lines

/*things.h*/

#ifndef _THINGS__H_
#define _THINGS_H_
/*rest of include file*/
#endif
the standard C header files uses the #ifndef technique to avoid
multiple file inclusions.
One problem is to make sure that identifier you have been testing
is not defined elsewhere.the usual solution is to use the file name
as the identifier,usin g UPPER CASE,replacing periods with under score,
and an underscore(or perhaps two underscores) as a prefix and suffix

Martin ambuhl wrote
#include <io.h>
There is no header <io.h> in standard C.
#include <conio.h>


There is no header <conio.h> in standard C.

[...]

and use a number of non-standard functions: clrscr(), filelength(),
fileno(), fnsplit(),
getch(). God knows what other garbage is to be found in this horror.

You should have noted the point:: the program was run on turbo C++
3.0 compiler ,and it was designed with that compiler in mindset

Dec 21 '05 #5
Here is the decoder program
#ifndef _DHUFF_H_
#define _DHUFF_H_

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

typedef struct node
{
unsigned char c;
unsigned long int freq;
struct node *up,*left,*righ t;
}sn;
typedef struct ftable
{
unsigned long int freq;
}sft;

/*Global variable declarations ***/
sft ft;
sn leaf[256];
sn *t[256];
int buf[50],bc;

/*Function prototype declarations*/
int getnodecount();
/*operation gets the count of the nodes*/
/*pre condition all nodes are sorted*/
/*post condition gets the count of nodes with non zero frequency*/

int sortnode(int);
/*operation performs sorting operation*/
/*pre condition all initialization fn are over*/
/*post condition pointer nodes are being created in decreasing order
of frequencies*/

int createtree();
/*operation creates huffman tree*/
/*pre condition all initialization fn are over*/
/*post condition huffman tree is being created for decoding purposes*/

int retrieveft(char *);
/*operation retrieves frequency table written by encoding program*/
/*pre condition all leave nodes should be initialized*/
/*post condition frequency values of all leaves are initialized*/

void initialize();
/*operation performs initialization function*/
/*pre condition compressed file should be opened*/
/*post condition character values of all leaves are set,rest set to
null,pointer array initialized*/

void addtobuffer(int );
/*operation stores huffman code in buffer*/
/*pre condition freq table file name,stored in file should be
skipped*/
/*post condition bit representation is stored in the buffer for each
character read*/

void refreshbuffer(F ILE *);
/*operation performs decoding operation*/
/*pre condition bit buffer should be set*/
/*post condition writes the ascii character to file*/

void relinkandfree() ;
/*operation frees allocated memory*/
/*pre condition decompressing operation completed*/
/*post condition returns allocated memory to heap*/

sn* allocate();
/*operation allocates memory*/
/*pre condition no heap fragmentation*/
/*post condition allocates memory from heap*/

#endif
#include "dhuff.h"

int main(void)
{
char filename[100],outfile[100];
FILE *p,*q;
int ch,ct;
long int filelen,count=1 024;
clrscr();

printf("\nFile decompressor for files compressed with comp.c");
printf("\nEnter the filename:");
fgets(filename, 100,stdin);
filename[strlen(filename )-1]=0;

initialize();
if(retrieveft(f ilename)==-1)
{
printf("\nCould not open file");
return -1;
}
createtree();

p = fopen(filename, "rb");
fseek(p,1024,SE EK_SET);
ct = fgetc(p);
fread(outfile,c t,1,p); /***Filename retrieval finished*/
fclose(p);
p = fopen(filename, "rb");

/***check for user renaming of output file*/
printf("\nThe specified archive contains a compressed file called
%s",outfile);

q = fopen(outfile," wb");
if(q==NULL && p==NULL)
{
printf("\nCould not open one or more files");
fclose(p);
fclose(q);
return -1;
}

fseek(p,256*siz eof(struct ftable)+1+ct,SE EK_SET);
filelen = filelength(file no(p));//non std fn
count = 1024 + 1 + ct;
printf("\n\nIni tialization over.\nPreparin g to decompress..");
//printf("\nDecom pressing....");
while(ch=fgetc( p),count++,ch!= EOF)
{

if(count==(file len-1))
{
addtobuffer(ch) ;
bc -= 8;
bc += fgetc(p);
refreshbuffer(q );
while(bc!=0)
refreshbuffer(q );
}
else
{
addtobuffer(ch) ;
refreshbuffer(q );
}
}

printf("\nDecom pression complete.\n");
printf("\nCreat ed output file %s ",outfile);
//relinkandfree() ;
return 0;
}

int getnodecount()
{
int i,h=0;
for(i=0;i<256;i ++)
{
if(!(leaf[i].freq))
h++;
}
return (255-h);
}
int sortnode(int z)/*sorts upto t[z] and not t[z-1]*/
{
int j,k;
sn* b;
for(k=0;k<=z;k+ +)
for(j=(k+1);j<= z;j++)
{
if((t[k]->freq)<(t[j]->freq))
{
b = t[k];
t[k] = t[j];
t[j] = b;
}
}
return 0;
}

int createtree()
{
int i;
sn *a;
sortnode(255);

for(i=getnodeco unt();i>0;i--)
{
sortnode(i);
a = NULL;
a = allocate();
a->freq = (t[i]->freq)+(t[i-1]->freq);
a->right = t[i];
a->left = t[i-1];
a->up = NULL;
a->c = '\0';
t[i]->up = a;
t[i-1]->up = a;
t[i-1] = a;
}
return 0;
}

void initialize()
{
int i;
for(i=0;i<256;i ++)
{
leaf[i].c = (unsigned char)i;
leaf[i].freq = 0;
leaf[i].up = NULL;
leaf[i].left = NULL;
leaf[i].right = NULL;
t[i] = &leaf[i];
}
return;
}

int retrieveft(char *filename)
{
int i;
FILE *fp;
if(!(fp = fopen(filename, "rb")))
return -1;/*Could not open file */

for(i=0;i<256;i ++)
{
fread(&ft,sizeo f(sft),1,fp);
leaf[i].c = (unsigned char)i;
leaf[i].freq = ft.freq;
leaf[i].up = NULL;
leaf[i].right = NULL;
leaf[i].left = NULL;
}
fclose(fp);
return 0;
}

void addtobuffer(int c)
{
int i = 0,bct =-1;
int buft[20],buftv[20];

while(c)
{
buft[++bct]=(c%2);
c/=2;
}
for(i=(bct+1);i <8;buft[i]=0,i++);
for(i=(0);i<8;b uftv[7-i]=buft[i],i++);
for(i=0;i<8;buf[bc+i]=buftv[i],i++);
bc+=8;
}

void refreshbuffer(F ILE *p)
{
sn *a;
int count=0,j,i;
a = t[0];

for(i=0;i<=bc;i ++)
{
if(a->left==NULL && a->right==NULL)
{
fputc(a->c,p);
for(j=count;j<b c;j++)
buf[j-count]=buf[j];

bc -= count;
count = 0;
a = t[0];
}
else if(buf[count]==0)
{
a = a->left;
count++;
}
else if(buf[count]==1)
{
a = a->right;
count++;
}
else
printf("\nError ");

}
return;
}

sn* allocate()
{
sn *p;
p = malloc(sizeof(s n));
if(!p)
{
printf("\nMemor y allocation error...");
printf("\n press any key to continue....");
getch();
exit(1);
}
return p;
}

/* void relinkandfree()
{
call getnodecount() then try to free
int i;
for(i=0;i<256;i ++)
{
t[i] -> up = NULL;
t[i] -> left = NULL;
t[i] -> right = NULL;
free(t[i]);
}
}*/

Dec 21 '05 #6
aa*****@gmail.c om wrote:
the following is the explanation given in the text book
C primer plus 3rd edition by stephen prata page no: 579
Well, it's wrong. Chalk up another purported C book (and author) to
be wary of.
[OP quoting from the above text]
One problem is to make sure that identifier you have been testing
is not defined elsewhere.the usual solution is to use the file name
as the identifier,usin g UPPER CASE,replacing periods with under score,
and an underscore(or perhaps two underscores) as a prefix and suffix ^^^^^^^^^^^
Apparently Mr. Prata could benefit from reading Martin's post as well.
You should have noted the point:: the program was run on turbo C++
3.0 compiler ,and it was designed with that compiler in mindset


You should have read the FAQ and welcome messages for this group.

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 21 '05 #7
aa*****@gmail.c om wrote:

Please follow the advice at http://cfaj.freeshell.org/google/ on how to
quote properly using Google Groups. The way you have quoted by copying
and pasting is confusing for people used to the conventional method.
Martin ambuhl wrote
/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_
The above makes it look like Martin Ambuhl wrote the header since there
is no other attibution, when it was actually you in a previous post.
I'll fix the quoting this time, but a lot of people on seeing such posts
will decide it just is not worth their efforts.

aa*****@gmail.c om wrote:
Martin ambuhl wrote
aa*****@gmail.c om wrote:
/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_
The above illustrates a very bad idea, using identifiers that begin
with
an underscore. Beginning identifiers with an underscore followed by an
uppercase letter is even worse. Avoid such things unless you *know*
when such things do not invade the namespace reserved to the
implementation. "HUFF_H" would have done as well.


Reply::

the following is the explanation given in the text book
C primer plus 3rd edition by stephen prata page no: 579

#ifndef directive is commonly used to prevent multiple inclusions of
a file.


This is true.
that is a header file can be set up in the following lines

/*things.h*/

#ifndef _THINGS__H_
#define _THINGS_H_
/*rest of include file*/
#endif
People may do this, but it is definitely and categorically WRONG. All
identifiers starting with an underscore followed by an upper case letter
are reserved for the implementation. You should not ever use them unless
you are using some implementation specific extension and the
documentation for your implementation EXPLICITLY tells you to use one,
and then you should only use it as your implementation says and reallise
that the code is completely non-portable.

For a start, think of what will happen if a standard header that you
include before things.h defines _THINGS_H_. I'll tell you what happens,
you end up missing out all the stuff that your things.h header was meant
to give you. This is just the simplest way it could go wrong, there are
an infinite number of other ways it could break things for you.
the standard C header files uses the #ifndef technique to avoid
multiple file inclusions.
This may be true (and often is), how the standard headers are written is
entirely specific to each individual implementation. They don't even
have to be real files!
One problem is to make sure that identifier you have been testing
is not defined elsewhere.the usual solution is to use the file name
as the identifier,usin g UPPER CASE,replacing periods with under score,
and an underscore(or perhaps two underscores) as a prefix and suffix


You use a convention and stick to it. However, use a convention that is
actually allowed by C. I don't care what your book says, the C STANDARD
says that names starting with an underscore followed by an upper case
letter are reserved for the implementation. In fact, because the rules
for names starting with an underscore are not as simple as they might be
it is best to avoid ALL names starting with an underscore at all times.
#include <io.h>


There is no header <io.h> in standard C.
#include <conio.h>


There is no header <conio.h> in standard C.

[...]

and use a number of non-standard functions: clrscr(), filelength(),
fileno(), fnsplit(),
getch(). God knows what other garbage is to be found in this horror.


You should have noted the point:: the program was run on turbo C++
3.0 compiler ,and it was designed with that compiler in mindset


We only deal with standard C, we don't deal with the extensions of all
the many systems out there. If you want to deal with stuff specific to
Turbo C++ 3.0 then discuss it on a boreland or possibly microsoft news
group.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 21 '05 #8
aa*****@gmail.c om wrote:
Martin ambuhl wrote
/*beginning of header file huff.h*/
#ifndef _HUFF_H_
#define _HUFF_H_


The above illustrates a very bad idea, using identifiers that begin
with
an underscore. Beginning identifiers with an underscore followed by
an uppercase letter is even worse. Avoid such things unless you know
when such things do not invade the namespace reserved to the
implementation. "HUFF_H" would have done as well.
Reply::

the following is the explanation given in the text book

It looks like you are trying to quote (a good thing) using Google (a
bad thing). Please see the information in the .sig below for the
correct way.
Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Dec 21 '05 #9
On 21 Dec 2005 12:10:14 -0800, in comp.lang.c , aa*****@gmail.c om
wrote:

the standard C header files uses the #ifndef technique to avoid
multiple file inclusions.
This is true. Furthermore they're allowed to use the leading
underscore and capital letter. You're not, because you're not part of
the implementation.
You should have noted the point:: the program was run on turbo C++
3.0 compiler ,and it was designed with that compiler in mindset


Interesting but not relevant in CLC, where code is expected to be
compiler-independent.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 22 '05 #10

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

Similar topics

3
5367
by: dot | last post by:
Hi all, I have written a Python huffman Encoding Module, for my own amusement. I thought it might be educational/entertaining for other people, so I've put it on my website and wrote about it a little. http://gumuz.looze.net/wordpress/index.php/archives/2004/11/25/huffman-encoding/ Your comments are highly appreciated! cheers,
0
501
by: rockstar1971 | last post by:
Hello. I’m working with the Windows Media Encoder SDK to create an online jukebox for myself, but I’m having problems getting it to work. Here’s what I want to do: I’ve got a large collection of mp3 files that I listen to at work from my home server. I simply share them out from IIS and then open playlist files in WMP to play lists...
8
5636
by: dirgesh | last post by:
I am having a hard time making a Program in C/C++ that uses the Huffman Compression to compress a file. I have a file "Hello World" That i need to compress. can someone please give me an example of how to do it with huffman compression.
8
9616
by: james | last post by:
I have ran into a little snag on an old database application I am converting. Out of 63 tables(all seperate files) , two of them are compressed using Huffman Compression. I have been searching all over the net (don't hit me too hard if you know a place I didn't look) and MSDN and cannot find anything that explains how to use Huffman in...
0
3785
by: Crisco www.misericordia.com.br | last post by:
Hi, friends! I am develop a simple encoder app, one form with one button that start the encoder. This is my code: ============================================================= Option Explicit On
0
2800
by: Crisco www.misericordia.com.br | last post by:
Hi I m working on WEBRADIO Software. im using Windows media encoder 9 SDK on Windows 2003 server using VB.NET. My current scenario is my soundcard . My application will push my server the live audio on specific port. I am using Windows media encoder sdk sample (entire code), currently i
11
6765
by: KWSW | last post by:
The other thread got too long so decided to start a new one. Got my huffman tree working and am now moving onto encoding and decoding my given text file. My idea now is to print out all the leaf nodes into a string and split them up using tokens to get my ascii value and the huffman code and store into a collection for reference when encoding....
5
8049
by: recordlovelife | last post by:
So i have written a code to encode a string of a select amount of letters into huffman code. #include <iostream> #include <string> using namespace std; string Huffman(char letter); string Huffman_word(string word);
0
5379
by: coucchy | last post by:
Hello everyone, i'm writing a C program that will read a text file and then encode the characters using huffman algorithm. So far i've read the files, built a tree, and now I'm building the strings to be used in encoding, Where i'm having problem is my BuildStrings function, instead of printing the 0s and 1s I appended to the array it outputs a...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
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...
0
5223
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...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
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
0
946
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...

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.