I'm doing a character count via char c = cin.get()
. Example of my output would be:
a: 53
b: 32
c: 29 etc..
For one of the alphabets, I'm getting an insanely large 9-digit number. And then when I use another input file that has more characters, the numbers are 6-digits and too large to be accurate. Any thoughts of this phenotype?
Again, sorry it's crunch time with the end of the semester. I appreciate any help out there.
int main (int argc, char *argv[])
{
int count [26] = { };
char alpha [26] = { };
char c;
c = cin.get();
while(!cin.eof())
{
if (isalpha(c))
{
c = tolower(c);
}
count [ c - 'a']++;
alpha [ c - 'a'] = c;
c = cin.get();
}
for ( int i = 0; i<26; i++ )
{
cout << alpha[i] << ":" << count[i] << endl;
}
} //end main
Here's the output: (edited)
a:224
b:50
c:70
d:20
e:167772180
f:10
g:40
h:66
i:28
Here's the input: (edited)
aaaaaaaaAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBBB
Made these changes, but it's still "hanging":
c = cin.get();
while(c=cin.get())
{
c = tolower(c);
if (isalpha(c))
continue;
count [ c - 'a']++;
alpha [ c - 'a'] = c;
}
for ( int i = 0; i<26; i++ )
{
cout << alpha[i] << ":" << count[i] << endl;
}
} //end main