I have a text file called A.txt that I am trying to read each character frequency from. The best way to show my problem is by example. Say the file reads "AbCAAb",
I have created an array of 256 memory positions to store each character frequency. So, first we encounter a capital A, which is the ascii value 65. So I go to position 65 in the array, and increment the count to 1. Then little b is 97, so I go to position 97 in the array...once I hit the next capital A, it should go to position 65 in the array and increment its counter to 2, then 3 for the next A. In the end, I should have an array consisting of zeros, where there were some characters that were not found in the file, and the frequencies of characters in the file that were found.
*************** *************** *************** *************** **********
THIS IS MY CODE THUS FAR
*************** *************** *************** *************** **********
//ignore the test points, they are for debugging purposes
I have created an array of 256 memory positions to store each character frequency. So, first we encounter a capital A, which is the ascii value 65. So I go to position 65 in the array, and increment the count to 1. Then little b is 97, so I go to position 97 in the array...once I hit the next capital A, it should go to position 65 in the array and increment its counter to 2, then 3 for the next A. In the end, I should have an array consisting of zeros, where there were some characters that were not found in the file, and the frequencies of characters in the file that were found.
*************** *************** *************** *************** **********
THIS IS MY CODE THUS FAR
*************** *************** *************** *************** **********
//ignore the test points, they are for debugging purposes
Code:
int getFrequency(int arrayOfCharacters[])
{
ifstream in;
in.open("A.txt");
cout<<"TEST POINT 2\n";
for(int i = 0; i < 256; i++)
{
arrayOfCharacters[i] = 0;
}
cout<<"TEST POINT 3\n";
int c = in.get();
arrayOfCharacters[c]++;
while(c!=EOF)
{
c = in.get();
arrayOfCharacters[c]++;
}
for(int j = 0; j < 256; j++)
{
cout<<arrayOfCharacters[c];
}
in.close();
return c;
}
Comment