Click here to Skip to main content
15,891,567 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How does Google Chrome Installer gets installed with UAC Prompt Pin
Raj Aryan 10011-May-11 23:25
Raj Aryan 10011-May-11 23:25 
Questionerror message Pin
Cyclone_S1-May-11 21:22
Cyclone_S1-May-11 21:22 
AnswerRe: error message Pin
ShilpiP1-May-11 22:04
ShilpiP1-May-11 22:04 
AnswerRe: error message Pin
Niklas L2-May-11 7:59
Niklas L2-May-11 7:59 
GeneralRe: error message Pin
Cyclone_S3-May-11 11:21
Cyclone_S3-May-11 11:21 
QuestionMFC: ownderdrawn menu, how can I change the default menu border? Pin
Erik1-May-11 19:53
Erik1-May-11 19:53 
AnswerRe: MFC: ownderdrawn menu, how can I change the default menu border? Pin
Hans Dietrich1-May-11 20:14
mentorHans Dietrich1-May-11 20:14 
QuestionPrinting out characters from a file Pin
Francis Paran1-May-11 14:14
Francis Paran1-May-11 14:14 
I recently have my huffman coding work by storing all of the character frequencies in an array sorted. The coding gives me the correct binary string for each character, but that is just for the characters in the array. What if I want to encode and display the binary characters coming from how they are arranged in the file itself?

Basically, my idea is that get each of these characters in the file and store them in a char string so that I can encode them from that point on. However, my program is weird because it outputs some characters but most are just blank. This is a section of the code that gets the characters from an input file and store them into a character array. counts_char is a function that gets the frequencies of each character; it also makes its instance of an input file stream.

char *stringChar;
    
    ifstream infile( "project2input.txt" );
    infile.seekg (0, ios::end);
    size = infile.tellg();
    stringChar = new char[size];
    while(!infile.eof())
          infile>>noskipws>>stringChar;
    infile.close();
    
    counts = new int[256];
    count_chars( counts );
    
    for (int k = 0; k<size; k++)
        cout<<stringChar[k];


The output looks like this:
l ░↨l





















♦ ^♂ É l É l 8 l 8 l 0l ╨














List of characters in the file with their frequencies:

E (0.0351617)
J (0.0351617)
- (0.0351617)
0 (0.0351617)
2 (0.0351617)
3 (0.0351617)
4 (0.0351617)
5 (0.0351617)
6 (0.0351617)
7 (0.0351617)
8 (0.0351617)
9 (0.0351617)
I (0.0703235)
M (0.0703235)
N (0.0703235)
O (0.0703235)
U (0.0703235)
W (0.0703235)
q (0.0703235)
z (0.0703235)
G (0.0703235)
1 (0.0703235)
T (0.105485)
k (0.105485)
C (0.175809)
x (0.21097)
; (0.246132)
j (0.246132)
S (0.281294)
. (0.351617)
A (0.457103)
v (0.703235)
w (0.914205)
g (0.949367)
y (1.16034)
, (1.6526)
f (1.86357)
b (1.89873)
u (1.9339)
m (2.00422)

(2.03938)
p (2.14487)
c (2.391)
d (2.63713)
l (3.41069)
h (3.44585)
s (4.99297)
i (5.16878)
r (5.30942)
a (5.37975)
o (5.66104)
n (5.9775)
t (6.8917)
e (10.9001)
(15.225)

2899 characters

Char Symbol Codes:


E = 0000000000000000000000000000000000000000000000000000001

J = 000000000000000000000000000000000000000000000000000001

- = 00000000000000000000000000000000000000000000000000001

0 = 0000000000000000000000000000000000000000000000000001

2 = 000000000000000000000000000000000000000000000000001

3 = 00000000000000000000000000000000000000000000000001

4 = 0000000000000000000000000000000000000000000000001

5 = 000000000000000000000000000000000000000000000001

6 = 00000000000000000000000000000000000000000000001

7 = 0000000000000000000000000000000000000000000001

8 = 000000000000000000000000000000000000000000001

9 = 00000000000000000000000000000000000000000001

I = 0000000000000000000000000000000000000000001

M = 000000000000000000000000000000000000000001

N = 00000000000000000000000000000000000000001

O = 0000000000000000000000000000000000000001

U = 000000000000000000000000000000000000001

W = 00000000000000000000000000000000000001

q = 0000000000000000000000000000000000001

z = 000000000000000000000000000000000001

G = 00000000000000000000000000000000001

1 = 0000000000000000000000000000000001

T = 000000000000000000000000000000001

k = 00000000000000000000000000000001

C = 0000000000000000000000000000001

x = 000000000000000000000000000001

; = 00000000000000000000000000001

j = 0000000000000000000000000001

S = 000000000000000000000000001

. = 00000000000000000000000001

A = 0000000000000000000000001

v = 000000000000000000000001

w = 00000000000000000000001

g = 0000000000000000000001

y = 000000000000000000001

, = 00000000000000000001

f = 0000000000000000001

b = 000000000000000001

u = 00000000000000001

m = 0000000000000001


= 000000000000001

p = 00000000000001

c = 0000000000001

d = 000000000001

l = 00000000001

h = 0000000001

s = 000000001

i = 00000001

r = 0000001

a = 000001

o = 00001

n = 0001

t = 001

e = 01

= 1

The portion before the list of characters is the one where the characters are supposed to be printed out as they were in the file.

Please help me with this. Thank you.
QuestionRe: Printing out characters from a file Pin
David Crow1-May-11 14:55
David Crow1-May-11 14:55 
AnswerRe: Printing out characters from a file Pin
Francis Paran2-May-11 9:45
Francis Paran2-May-11 9:45 
Questionhow to convert images through C++ Pin
aesthetic.crazy1-May-11 7:21
aesthetic.crazy1-May-11 7:21 
AnswerRe: how to convert images through C++ Pin
enhzflep1-May-11 7:35
enhzflep1-May-11 7:35 
GeneralRe: how to convert images through C++ Pin
Rajesh R Subramanian1-May-11 9:15
professionalRajesh R Subramanian1-May-11 9:15 
AnswerRe: how to convert images through C++ Pin
jeff61-May-11 11:59
jeff61-May-11 11:59 
AnswerRe: how to convert images through C++ Pin
«_Superman_»1-May-11 16:46
professional«_Superman_»1-May-11 16:46 
AnswerRe: how to convert images through C++ Pin
Cool_Dev1-May-11 19:15
Cool_Dev1-May-11 19:15 
AnswerRe: how to convert images through C++ Pin
Chris Losinger2-May-11 15:05
professionalChris Losinger2-May-11 15:05 
Question'x' bit OS Pin
Pranit Kothari1-May-11 2:21
Pranit Kothari1-May-11 2:21 
AnswerRe: 'x' bit OS PinPopular
«_Superman_»1-May-11 3:00
professional«_Superman_»1-May-11 3:00 
GeneralRe: 'x' bit OS Pin
Pranit Kothari1-May-11 3:14
Pranit Kothari1-May-11 3:14 
GeneralRe: 'x' bit OS Pin
Pranit Kothari10-May-11 22:40
Pranit Kothari10-May-11 22:40 
GeneralRe: 'x' bit OS Pin
«_Superman_»10-May-11 22:59
professional«_Superman_»10-May-11 22:59 
Questionproblem Pin
hmaz462930-Apr-11 23:49
hmaz462930-Apr-11 23:49 
AnswerRe: problem Pin
Rajesh R Subramanian1-May-11 0:01
professionalRajesh R Subramanian1-May-11 0:01 
AnswerRe: problem Pin
«_Superman_»1-May-11 2:16
professional«_Superman_»1-May-11 2: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.