Hi every body...
this(attachment) is my code for implemention of Huffman code,this code must read every file and compress them,
it works on many test file but if I input test.txt it give an Error...
How can i solve this error ...
and the next problem is if we input a gif file (for instance 1.gif) it doesn't give any output!..
Can any body help me how to change the code to read for every file ?
I excuse for my question that take up much time!...
(I am so ashamed but I can't find any remedy!)
tnx so much.

Well right at the start
Huffman::Huffman
end is uninitialised.

Then later on...

long begin,end;
    begin = output.tellg();
    output.seekg (0, ios::end);
    end = output.tellg();

This local variable shadows your member variable, and you're still out of luck.

excuse me,I didn't understand your help!...
I think uninitialized end doesn't make any problem...
May you correct the mistakes and upload cpp file again ?
tnx.

> I think uninitialized end doesn't make any problem...
Well you could try printing it as well, just to see how badly you're screwing up.

> May you correct the mistakes and upload cpp file again ?
Nope.
We point out problems, you fix them.

Well right at the start
Huffman::Huffman
end is uninitialised.

Then later on...

long begin,end;
    begin = output.tellg();
    output.seekg (0, ios::end);
    end = output.tellg();

This local variable shadows your member variable, and you're still out of luck.

If you notice I have initialized end in readFile() function.
May you explain more ?...
where must i add this code ? and what how can i solve other problems that i mentioned.

<<nevermind, I have nothing to add to this discussion - code is too messy>>

It's uninitialised in the constructor(which is the FIRST thing that happens), then you promptly go and USE that value in your constructor.

Your program is now all but dead, and any results you may see after this point are suspect.

But Notice that the first thing in constructor is readFile.and it initializes it.

Here are some things to consider looking into:

--- Module: main.cpp (C++)
main.cpp 38 error 1551: (Warning -- Function may throw exception '...' in destructor 'Huffman::~Huffman(void)')
main.cpp 39 error 1540: (Warning -- Pointer member 'Huffman::codes_list' (line 69) neither freed nor zeroed by destructor)
main.cpp 69 error 830: (Info -- Location cited in prior message)
main.cpp 39 error 1540: (Warning -- Pointer member 'Huffman::list' (line 71) neither freed nor zeroed by destructor)
main.cpp 71 error 830: (Info -- Location cited in prior message)
main.cpp 39 error 1540: (Warning -- Pointer member 'Huffman::tree_list' (line 72) neither freed nor zeroed by destructor)
main.cpp 72 error 830: (Info -- Location cited in prior message)
main.cpp 39 error 1540: (Warning -- Pointer member 'Huffman::memblock' (line 75) neither freed nor zeroed by destructor)
main.cpp 75 error 830: (Info -- Location cited in prior message)
main.cpp 84 error 1732: (Info -- new in constructor for class 'Huffman' which has no assignment operator)
main.cpp 84 error 1733: (Info -- new in constructor for class 'Huffman' which has no copy constructor)
main.cpp 84 error 737: (Info -- Loss of sign in promotion from int to unsigned long)
main.cpp 85 error 737: (Info -- Loss of sign in promotion from int to unsigned long)
main.cpp 99 error 725: (Info -- Expected positive indentation from line 98)
main.cpp 98 error 830: (Info -- Location cited in prior message)
main.cpp 100 error 725: (Info -- Expected positive indentation from line 98)
main.cpp 98 error 830: (Info -- Location cited in prior message)
main.cpp 101 error 725: (Info -- Expected positive indentation from line 98)
main.cpp 98 error 830: (Info -- Location cited in prior message)
main.cpp 102 error 725: (Info -- Expected positive indentation from line 98)
main.cpp 98 error 830: (Info -- Location cited in prior message)
main.cpp 103 error 725: (Info -- Expected positive indentation from line 98)
main.cpp 98 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::codes_list' (line 69) not initialized by constructor)
main.cpp 69 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::heap_size' (line 70) not initialized by constructor)
main.cpp 70 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::size' (line 70) not initialized by constructor)
main.cpp 70 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::length' (line 70) not initialized by constructor)
main.cpp 70 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::list' (line 71) not initialized by constructor)
main.cpp 71 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::tree_list' (line 72) not initialized by constructor)
main.cpp 72 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::root' (line 73) not initialized by constructor)
main.cpp 73 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::left_chars' (line 74) not initialized by constructor)
main.cpp 74 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::memblock' (line 75) not initialized by constructor)
main.cpp 75 error 830: (Info -- Location cited in prior message)
main.cpp 112 error 1401: (Warning -- member 'Huffman::end' (line 76) not initialized by constructor)
main.cpp 76 error 830: (Info -- Location cited in prior message)
main.cpp 117 error 725: (Info -- Expected positive indentation from line 116)
main.cpp 116 error 830: (Info -- Location cited in prior message)
main.cpp 118 error 1762: (Info -- Member function 'Huffman::padding(char, int)' could be made const)
main.cpp 134 error 725: (Info -- Expected positive indentation from line 133)
main.cpp 133 error 830: (Info -- Location cited in prior message)
main.cpp 137 error 1762: (Info -- Member function 'Huffman::find_symbol(char)' could be made const)
main.cpp 183 error 1762: (Info -- Member function 'Huffman::print(void)' could be made const)
main.cpp 189 error 1762: (Info -- Member function 'Huffman::swap(struct Node &, struct Node &)' could be made const)
main.cpp 200 error 530: (Warning -- Symbol 'tmp2' (line 195) not initialized)
main.cpp 195 error 830: (Info -- Location cited in prior message)
main.cpp 204 error 725: (Info -- Expected positive indentation from line 203)
main.cpp 203 error 830: (Info -- Location cited in prior message)
main.cpp 205 error 725: (Info -- Expected positive indentation from line 203)
main.cpp 203 error 830: (Info -- Location cited in prior message)
main.cpp 209 error 1762: (Info -- Member function 'Huffman::find_dissimilar_chars(void)' could be made const)
main.cpp 266 error 725: (Info -- Expected positive indentation from line 264)
main.cpp 264 error 830: (Info -- Location cited in prior message)
main.cpp 273 error 1746: (Info -- parameter 'code' in function 'Huffman::set_code(struct Node *, std::basic_string<char>)' could be made const reference)
main.cpp 273 error 818: (Info -- Pointer parameter 'current_Node' (line 255) could be declared as pointing to const)
main.cpp 255 error 830: (Info -- Location cited in prior message)
main.cpp 283 error 1762: (Info -- Member function 'Huffman::find_sym(char)' could be made const)
main.cpp 306 error 732: (Info -- Loss of sign (arg. no. 2) (int to unsigned long))
main.cpp 307 error 732: (Info -- Loss of sign (arg. no. 2) (int to unsigned long))
main.cpp 316 error 744: (Info -- switch statement has no default)
main.cpp 325 error 423: (Warning -- Creation of memory leak in assignment to 'Huffman::list')
main.cpp 326 error 423: (Warning -- Creation of memory leak in assignment to 'Huffman::tree_list')
main.cpp 327 error 423: (Warning -- Creation of memory leak in assignment to 'Huffman::codes_list')
main.cpp 337 error 734: (Info -- Loss of precision (assignment) (31 bits to 7 bits))
main.cpp 349 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 361 error 747: (Info -- Significant prototype coercion (arg. no. 1) long to long long)
main.cpp 362 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 363 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 365 error 737: (Info -- Loss of sign in promotion from long to unsigned long)
main.cpp 366 error 747: (Info -- Significant prototype coercion (arg. no. 1) long to long long)
main.cpp 377 error 701: (Info -- Shift left of signed quantity (int))
main.cpp 377 error 734: (Info -- Loss of precision (assignment) (14 bits to 7 bits))
main.cpp 382 error 701: (Info -- Shift left of signed quantity (int))
main.cpp 382 error 734: (Info -- Loss of precision (assignment) (8 bits to 7 bits))
main.cpp 389 error 725: (Info -- Expected positive indentation from line 387)
main.cpp 387 error 830: (Info -- Location cited in prior message)
main.cpp 389 error 701: (Info -- Shift left of signed quantity (int))
main.cpp 389 error 734: (Info -- Loss of precision (assignment) (14 bits to 7 bits))
main.cpp 394 error 701: (Info -- Shift left of signed quantity (int))
main.cpp 394 error 734: (Info -- Loss of precision (assignment) (8 bits to 7 bits))
main.cpp 414 error 744: (Info -- switch statement has no default)
main.cpp 428 error 578: (Warning -- Declaration of symbol 'end' hides symbol 'Huffman::end' (line 76))
main.cpp 76 error 830: (Info -- Location cited in prior message)
main.cpp 429 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 430 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 431 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 434 error 1762: (Info -- Member function 'Huffman::file_size1(void)' could be made const)
main.cpp 439 error 578: (Warning -- Declaration of symbol 'end' hides symbol 'Huffman::end' (line 76))
main.cpp 76 error 830: (Info -- Location cited in prior message)
main.cpp 440 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 441 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 442 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 446 error 1762: (Info -- Member function 'Huffman::file_size2(void)' could be made const)
main.cpp 450 error 578: (Warning -- Declaration of symbol 'root' hides symbol 'Huffman::root' (line 73))
main.cpp 73 error 830: (Info -- Location cited in prior message)
main.cpp 456 error 818: (Info -- Pointer parameter 'root' (line 450) could be declared as pointing to const)
main.cpp 450 error 830: (Info -- Location cited in prior message)
main.cpp 458 error 578: (Warning -- Declaration of symbol 'root' hides symbol 'Huffman::root' (line 73))
main.cpp 73 error 830: (Info -- Location cited in prior message)
main.cpp 463 error 525: (Warning -- Negative indentation from line 459)
main.cpp 459 error 830: (Info -- Location cited in prior message)
main.cpp 472 error 818: (Info -- Pointer parameter 'root' (line 458) could be declared as pointing to const)
main.cpp 458 error 830: (Info -- Location cited in prior message)
main.cpp 491 error 712: (Info -- Loss of precision (assignment) (long long to long))
main.cpp 492 error 737: (Info -- Loss of sign in promotion from long to unsigned long)
main.cpp 493 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 515 error 712: (Info -- Loss of precision (arg. no. 1) (long long to unsigned long))
main.cpp 515 error 747: (Info -- Significant prototype coercion (arg. no. 1) long long to unsigned long)
main.cpp 516 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 517 error 712: (Info -- Loss of precision (arg. no. 2) (long long to long))
main.cpp 517 error 747: (Info -- Significant prototype coercion (arg. no. 2) long long to long)
main.cpp 520 error 712: (Info -- Loss of precision (arg. no. 2) (long long to long))
main.cpp 520 error 747: (Info -- Significant prototype coercion (arg. no. 2) long long to long)
main.cpp 548 error 734: (Info -- Loss of precision (initialization) (31 bits to 7 bits))
main.cpp 553 error 701: (Info -- Shift left of signed quantity (int))
main.cpp 553 error 734: (Info -- Loss of precision (assignment) (31 bits to 7 bits))
main.cpp 561 error 747: (Info -- Significant prototype coercion (arg. no. 1) int to long long)
main.cpp 575 error 530: (Warning -- Symbol 'choice' (line 571) not initialized)
main.cpp 571 error 830: (Info -- Location cited in prior message)

Here are some things to consider looking into:

Can you say how you find this error?

Can you say how you find this error?

You find these errors by 'debugging' your code. I would recommend Visual C++, as it seems to be the easiest to use/most detailed in my personal opinion.

Ok,tnx I didn't have Visual C++ , but I liked to use that!..
I change my code compeletely and it works rather well..
Tnx for all of your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.