Letter counter from file

closed account (3UpjLyTq)
I have writen this code to count the number of time a letter that appears in a file. It should count both upper and lower case letters. I have written the code and compile it and there is no errors that come up. So when I run the code it come up with a error on a pop up window. The error reads run-timecheck failur#2- Stack around the variable 'number' was corrupted. So it cout out all of the data i tell it to. But it seems to not like my loop and does not want to count the letters in my file. I think the problem is with how I have set up my loop. In how it runs and were it starts. But I am not sure why it does not work. So here is the code form start to end. If some one could look it over for me that would help and give an idea about how to fix it that would be a great help please. It only cout what the each value of the variable that is before the loop and the loop for some reason does not change the value of the variable.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
double number[25];
int d, b, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
string HI;
ifstream inData;
inData.open("matt.txt");
getline(inData,HI);
b=HI.length();
A=1;
B=1;
C=1;
D=1;
E=1;
F=1;
G=1;
H=1;
I=1;
J=1;
K=1;
L=1;
M=1;
N=1;
O=1;
P=1;
Q=1;
R=1;
S=1;
T=1;
U=1;
V=1;
W=1;
X=1;
Y=1;
Z=1;
for ( d=0; (b-1)>=d; d++)
{
if ('a' || 'A')
{ A++;
number[0]=A;
}
if ( 'b' || 'B')
{ B++;
number[1]=B;
}
if ( 'c' || 'C')
{ C++;
number[2]=C;
}
if ( 'd' || 'D')
{ D++;
number[3]=D;
}
if ( 'e' || 'E')
{ E++;
number[4]=E;
}
if ( 'f' || 'F')
{ F++;
number[5]=F;
}
if ( 'g' || 'G')
{ G++;
number[6]=G;
}
if ( 'h' || 'H')
{ H++;
number[7]=H;
}
if ( 'i' || 'I')
{ I++;
number[8]=I;
}
if ( 'j' || 'J')
{ J++;
number[9]=J;
}
if ( 'k' || 'K')
{ K++;
number[10]=K;
}
if ( 'l' || 'L')
{ L++;
number[11]=L;
}
if ( 'm' || 'M')
{ M++;
number[12]=M;
}
if ( 'n' || 'N')
{ N++;
number[13]=N;
}
if ( 'o' || 'O')
{ O++;
number[14]=O;
}
if ( 'p' || 'P')
{ P++;
number[15]=P;
}
if ( 'q' || 'Q')
{ Q++;
number[16]=Q;
}
if ( 'r' || 'R')
{ R++;
number[17]=R;
}
if ( 's' || 'S')
{ S++;
number[18]=S;
}
if ( 't' || 'T')
{ T++;
number[19]=T;
}
if ( 'u' || 'U')
{ U++;
number[20]=U;
}
if ( 'v' || 'V')
{ V++;
number[21]=V;
}
if ( 'w' || 'W')
{ W++;
number[22]=W;
}
if ( 'x' || 'X')
{ X++;
number[23]=X;
}
if ( 'y' || 'Y')
{ Y++;
number[24]=Y;
}
if ( 'z' || 'Z')
{ Z++;
number[25]=Z;
}
}

number[0]=A;
number[1]=B;
number[2]=C;
number[3]=D;
number[4]=E;
number[5]=F;
number[6]=G;
number[7]=H;
number[8]=I;
number[9]=J;
number[10]=K;
number[11]=L;
number[12]=M;
number[13]=N;
number[14]=O;
number[15]=P;
number[16]=Q;
number[17]=R;
number[18]=S;
number[19]=T;
number[20]=U;
number[21]=V;
number[22]=W;
number[23]=X;
number[24]=Y;
number[25]=Z;
cout << number[0] << "This is the number of letter's A that are is this text."<< endl;
cout << number[1] << "This is the number of letter's B that are is this text." << endl;
cout << number[2] << "This is the number of letter's C that are is this text." << endl;
cout << number[3] << "This is the number of letter's D that are is this text." << endl;
cout << number[4] << "This is the number of letter's E that are is this text." << endl;
cout << number[5] << "This is the number of letter's F that are is this text." << endl;
cout << number[6] << "This is the number of letter's G that are is this text." << endl;
cout << number[7] << "This is the number of letter's H that are is this text." << endl;
cout << number[8] << "This is the number of letter's I that are is this text." << endl;
cout << number[9] << "This is the number of letter's J that are is this text." << endl;
cout << number[10] << "This is the number of letter's K that are is this text." << endl;
cout << number[11] << "This is the number of letter's L that are is this text." << endl;
cout << number[12] << "This is the number of letter's M that are is this text." << endl;
cout << number[13] << "This is the number of letter's N that are is this text." << endl;
cout << number[14] << "This is the number of letter's O that are is this text." << endl;
cout << number[15] << "This is the number of letter's P that are is this text." << endl;
cout << number[16] << "This is the number of letter's Q that are is this text." << endl;
cout << number[17] << "This is the number of letter's R that are is this text." << endl;
cout << number[18] << "This is the number of letter's S that are is this text." << endl;
cout << number[19] << "This is the number of letter's T that are is this text." << endl;
cout << number[20] << "This is the number of letter's U that are is this text." << endl;
cout << number[21] << "This is the number of letter's V that are is this text." << endl;
cout << number[22] << "This is the number of letter's W that are is this text." << endl;
cout << number[23] << "This is the number of letter's X that are is this text." << endl;
cout << number[24] << "This is the number of letter's Y that are is this text." << endl;
cout << number[25] << "This is the number of letter's Z that are is this text." << endl;


return 0;
}

Number only contains 25 elements, but you are writing up to element 26.

i.e. Number[25] only gives you Number[0]~Number[24].
closed account (3UpjLyTq)
Thank you that got ride of the error but it now does not want to count the letter I thought that would fix it I think i need change how the loop runs a find them.
You if statements are always returning true.
if('A') {
Doesn't work. That will convert A to it's ASCII value, which is nonzero, so you will enter the if statement. What you want to do is compare the value you are looking at to 'A' using ==
closed account (3UpjLyTq)
I do not under stand what you mean by this. BUT let give it a try so what you are trying to say zhuge is that i need to set 'a' and 'A' == to some value if this ture then what value should i set it equal to.
I just posted something like this, for a code review (currently on page three) that might help you. Leppie
Topic archived. No new replies allowed.