Connecting Tech Pros Worldwide Forums | Help | Site Map

expected `;' before '{' token and expected `}' at end of input

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: Oct 3 '09
I have been trying to debug it for two hours now, Can anyone see why I am getting these two errors. Thanks!

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

# define Unlinked -1


struct {
unsigned Occurences;
BinCode Code;
int Link;
} HuffTable[CharSetLength];

FILE *SampleText, *CodeFile;




void ClearTable(void){
int i;
for (i = 0; i <CharSetLength; ++i) {
HuffTable[i].Occurences = 1;
HuffTable[i].Link = Unlinked;
HuffTable[i].Code.NumberOfBits = 0;
HuffTable[i].Code.Representation = 0;
}
}

void FindLeftAndRight(int *Left, int *Right){
int i, MinIndex = 0, MinValue = Infinity, NextMinIndex, NextMinValue,
Occurences;

for(i=0;i<CharSetLength;++i){
Occurences = HuffTable[i].Occurences;
if (Occurences < MinValue){
NextMinIndex = MinIndex;
NextMinValue = MinValue;
MinIndex = i ;
MinValue = Occurences;
}
else if (Occurences < NextMinValue) {
NextMinIndex = i;
NextMinValue = Occurences;
}
}
if (MinIndex < NextMinIndex){
*Left = MinIndex;
*Right = NextMinIndex;
}
else {
*Right = MinIndex;
*Left = NextMinIndex;
}
}

void AddBitToCodesLinkedTo(int Index, int Bit, int *ChainEnd){

do {
if (HuffTable[Index].Code.NumberOfBits == BitMax) {
printf ("too long to be represented in bits %d bits \n", BitMax);
exit(0);
}
HuffTable[Index].Code.Representation |=
(Bit << HuffTable[Index].Code.NumberOfBits ++ );
*ChainEnd = Index;
Index = HuffTable[Index].Link;
}while (Index!= Unlinked);
}


void OutputCodes(void) {
int i;

for (i = 0;i <CharSetLength; ++i)
fprintf(CodeFile, CodeFormat, HuffTable[i].Code.NumberOfBits,
HuffTable[i].Code.Representation);
}

main() {
char ch;
int NodesRemaining,Left,Right,ChainEnd;

ClearTable();
printf("Sample text file name?\n");
RequestAndOpenFile(&SampleText,"r");
printf("Code file name?\n");
RequestAndOpenFile(&CodeFile,"w");

while ((ch = getc(SampleText))!=EOF)
if (ch < CharSetLength)
if (HuffTable[ch].Occurences++ == Infinity){
printf ("Too many occurences of %c", ch);
exit(0);
}
for (NodesRemaining = CharSetLength; NodesRemaining > 1; --NodesRemaining) {
FindLeftAndRight {&Left, &Right);
HuffTable[left].Occurences += HuffTable[right].Occurences;
HuffTable[right].Occurences = Infinity;
AddBitToCodesLinkedTo(Left, 0 , &ChainEnd);
HuffTable[ChainEnd].Link = Right;
AddBitToCodesLinkedTo(Right, 1, &ChainEnd);
}
OutputCodes();
}

The first error shows up in the line

for (NodesRemaining = CharSetLength; NodesRemaining > 1; --NodesRemaining) {

and the second error shows up after
OutputCodes()

Thanks in advance

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: Oct 3 '09

re: expected `;' before '{' token and expected `}' at end of input


This doesn't appear to be the cause of your problem, but I suggest you put brackets around the while((ch=getc(SampleText)) != EOF) and if (ch<CharSetLength) blocks to make sure these blocks encompass the statements you intend them to.

By the way,
main should be defined as int main(void) or void main(void).
ch should be an int rather than a char.

In the future please use CODE tags when you post code: select your source code and then press the "#" button at the top of the dataentry window.
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,382
#3: Oct 3 '09

re: expected `;' before '{' token and expected `}' at end of input


You might touch up this line just a tad:

Expand|Select|Wrap|Line Numbers
  1. FindLeftAndRight {&Left, &Right);
Newbie
 
Join Date: Oct 2009
Posts: 2
#4: Oct 3 '09

re: expected `;' before '{' token and expected `}' at end of input


Thanks a lot for the replies Donbock and weaknessforcats.
Sorry about not using the code tags.

@Weakness : LOL that mistake was silly!! and I have been trying to fix it for 2 hours!!!

Note to myself: { and ( looks similar in Dev C+ at first glance.

That was quite stupid of me anyway.
again, thanks ..this is a great community!
Reply