Click here to Skip to main content
15,890,385 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ADO recordset moveNext abnormal Pin
barneyman29-Apr-11 17:13
barneyman29-Apr-11 17:13 
GeneralRe: ADO recordset moveNext abnormal Pin
Jokcy30-Apr-11 4:40
Jokcy30-Apr-11 4:40 
QuestionWriting to the console only (without re-direction) Pin
Member 385202428-Apr-11 12:00
Member 385202428-Apr-11 12:00 
AnswerRe: Writing to the console only (without re-direction) Pin
Hans Dietrich28-Apr-11 12:09
mentorHans Dietrich28-Apr-11 12:09 
GeneralRe: Writing to the console only (without re-direction) Pin
Member 385202428-Apr-11 12:15
Member 385202428-Apr-11 12:15 
GeneralRe: Writing to the console only (without re-direction) Pin
Hans Dietrich28-Apr-11 12:20
mentorHans Dietrich28-Apr-11 12:20 
GeneralRe: Writing to the console only (without re-direction) Pin
Member 385202428-Apr-11 12:52
Member 385202428-Apr-11 12:52 
GeneralRe: Writing to the console only (without re-direction) Pin
Member 385202428-Apr-11 13:08
Member 385202428-Apr-11 13:08 
AnswerRe: Writing to the console only (without re-direction) Pin
Hans Dietrich28-Apr-11 13:12
mentorHans Dietrich28-Apr-11 13:12 
GeneralRe: Writing to the console only (without re-direction) Pin
Member 385202428-Apr-11 13:29
Member 385202428-Apr-11 13:29 
QuestionXML Parsing using Tiny XML Pin
pix_programmer28-Apr-11 3:55
pix_programmer28-Apr-11 3:55 
AnswerRe: XML Parsing using Tiny XML Pin
Code-o-mat28-Apr-11 4:10
Code-o-mat28-Apr-11 4:10 
AnswerRe: XML Parsing using Tiny XML Pin
jschell28-Apr-11 8:24
jschell28-Apr-11 8:24 
QuestionGenerating Huffman Coding using Two Queues and a Cursor Pin
Francis Paran28-Apr-11 3:45
Francis Paran28-Apr-11 3:45 
QuestionRe: Generating Huffman Coding using Two Queues and a Cursor Pin
David Crow28-Apr-11 9:04
David Crow28-Apr-11 9:04 
AnswerRe: Generating Huffman Coding using Two Queues and a Cursor Pin
Francis Paran28-Apr-11 12:17
Francis Paran28-Apr-11 12:17 
GeneralRe: Generating Huffman Coding using Two Queues and a Cursor Pin
David Crow29-Apr-11 4:01
David Crow29-Apr-11 4:01 
GeneralRe: Generating Huffman Coding using Two Queues and a Cursor Pin
Francis Paran29-Apr-11 6:25
Francis Paran29-Apr-11 6:25 
GeneralRe: Generating Huffman Coding using Two Queues and a Cursor Pin
David Crow29-Apr-11 8:20
David Crow29-Apr-11 8:20 
GeneralRe: Generating Huffman Coding using Two Queues and a Cursor Pin
Francis Paran29-Apr-11 10:31
Francis Paran29-Apr-11 10:31 
The thing is that I get the frequencies of the correct characters like this:

#include <iostream>
#include <fstream>

using namespace std;

int size, i, j;
void count_chars( int *counts );
double frequency (int char_count, int length);
void generateHuffman(Queue& q1, Queue& q2);

int main()
{
    char *stringChar;
    int *counts;
    ifstream infile( "project2input.txt" );
    infile.seekg (0, ios::end);
    
    int size = infile.tellg();
    
    stringChar = new char[size];
    
    for(i = 0; i<size; i++)
         infile.seekg(i)>>stringChar[i];
    
    infile.close();
 
    counts = new int[256];
    count_chars( counts );
    cout<<"\n\n";
    int newSize;
    
    for(j = 0; j<256; j++)
            if (counts[j] != 0)
            {  newSize++;
               cout<<(char) j<<"= "<<j<<" ("<<frequency (counts[j], 
                            size)*100<<")\n";
            }
            cout<<endl<<newSize<<" characters\n";
 
    cout<<endl;
    char c;
    cin>>c;
    
    return 0;
}
void count_chars( int *counts )
{
    for ( int i = 0 ; i <256 ; i++ )
        counts[ i ] = 0;
    
    ifstream file( "project2input.txt" );

    if ( !file ) {
        cerr <<"Couldn't open the input file!\n";
        throw "abort";
    }

    for ( ; ; ) 
    {
        unsigned char c;
        file>> c;    
        if ( file )   
           counts[ c ]++;
        else
            break;
   }
}


It seems like the positions of the character frequencies in counts, when converted into char and once output, will always show me the characters they represent. However, the problem comes with sorting them where it changes their positions in the array as well as the characters they will now represent.

I had the sort function in <algorithm> already figured out; now it is just sorting this array using that function, but at the same time still retaining the characters being represented by their frequencies in the file.

Putting the character and its frequency into a node really looks promising to me in solving any issues of sorting. My guess would be sorting nodes based on their frequency values, but am I right at this or am I just making things more complicated and worse by adding a little more overhead?
GeneralRe: Generating Huffman Coding using Two Queues and a Cursor Pin
David Crow2-May-11 2:51
David Crow2-May-11 2:51 
QuestionWindows 7 compatible code in VC++ MFC Pin
Janaiko28-Apr-11 3:34
Janaiko28-Apr-11 3:34 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Hans Dietrich28-Apr-11 4:10
mentorHans Dietrich28-Apr-11 4:10 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Albert Holguin28-Apr-11 8:41
professionalAlbert Holguin28-Apr-11 8:41 
AnswerRe: Windows 7 compatible code in VC++ MFC Pin
Andrew Phillips30-Apr-11 6:16
Andrew Phillips30-Apr-11 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.