Hello! cplusplus forum
I have a problem with the encoding part of RLE, I just started programming.
The problem is in the ´void coderen ()´ part. The thing i need to do is
encode things like:
abccccccddd to abc6d3
and if there are numbers: 123444455 -> 1\2\3\43\52
and every \ has to be coded with two backslashes \\
so \ \ \ \ -> \ \4 and \ \ \ \ \ -> \ \5
Some of the errors terminal gives in line 171, while my program only has 165!
I understand neither of the following errors:
ERRORS:
error: expected primary-expression before ‘=’ token
else ((kar !== '\\') || (kar !>= '0' && kar !<= '9'))
^
86:42: error: expected ‘)’ before ‘!’ token
else ((kar !== '\\') || (kar !>= '0' && kar !<= '9'))
^
171:1: error: expected ‘)’ at end of input
}
^
171:1: error: expected ‘;’ at end of input
171:1: error: expected ‘}’ at end of input
If anyone could help me out, that´d be great!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
void coderen (ifstream & invoer, ofstream & uitvoer)
{
int teller;
teller = 1;
char kar, prevkar;
kar = invoer.get();
prevkar = kar;
while (! invoer.eof())
{
if ((kar == '\\') || (kar >= '0' && kar <= '9'))
{
while (kar == '\\')
{
if (prevkar == kar)
{
teller++;
kar = kar + '\\';
uitvoer.put(kar);
}
else (prevkar != kar);
{
kar = kar + '\\';
uitvoer.put(kar);
}
}
while (kar >= '0' && kar <= '9')
{
if (prevkar == kar)
{
teller++;
kar = '\\' + kar + '\\';
uitvoer.put(kar);
}
else (prevkar != kar);
{
kar = kar;
uitvoer.put(kar);
}
}//while kar
}//if
else ((kar < '0' || kar > '9') && kar != '\n' && kar != '\\')
{
while (prevkar == kar)
{
teller++;
uitvoer.put(kar);
}
}
}//while eof
}//void
void decoderen (ifstream & invoer, ofstream & uitvoer)
{
int getal;
char kar, prevkar;//Variabelen om de in te lezen karakters
//in op te slaan
kar = invoer.get();
while (! invoer.eof())
{
getal = 0;
prevkar = kar;
uitvoer.put(kar);//Kar in doelfile zetten
kar = invoer.get();
while ((kar == '\\') || (kar >= '0' && kar <= '9'))
{ //while no letter
while (kar == '\\')
{ //While backslash
kar = invoer.get();
prevkar = kar;
uitvoer.put(kar);//Teken direct na '\\'
//moet geput worden
kar = invoer.get();//Controle of teken daarna '\\' is
}//while backslash
if (kar >= '0' && kar <= '9')
{ //Als letter n
//x herhaald wordt
getal = kar - '0';
kar = invoer.get();
while (kar >= '0' && kar <= '9')
{ //Herhaling bepaling
getal = (getal * 10) + kar - '0';
kar = invoer.get();
}
for (int i (1); i < getal; i++)
{ //Uitvoerprocedure
uitvoer.put(prevkar);
}
} //if getal
}//while no letter
}//while not endoffile
invoer.close();
uitvoer.close();
}//decoderen
//void compressie (int orgAantal, int uitvAantal)
//{
// int rate = (uitvAantal/orgAantal)*100;
// cout<<"cp is "<<rate<<"%"<<endl;
//}
int main ()
{
ifstream invoer;
ofstream uitvoer;
intro();
begin(invoer,uitvoer);
coderen (invoer,uitvoer);
// compressie(orgAantal, uitvAantal);
}
|