Counting Individual Letters In Text File & Print Results -Wrong Output c++
<p>I am trying to read in a file from the command line, read the characters into an array, count the characters individuality and print the results. the code compiles without any errors but the individual letter counts are much higher than they should be for large files and it does not count at all sometimes for small files. </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string.h&gt; 
#include &lt;cctype&gt; 
#include &lt;algorithm&gt;

using namespace std;


int main(int argc, char **argv){ 
if(argc !=2){
     cout &lt;&lt; "usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;filename&gt;\n";
}
else{
     ifstream myfile (argv[1]); 
     if(!myfile.is_open())  //check to see if file is opened.
        cout &lt;&lt; "Can not open your file\n";
    else{
        static int array[26];  //stores the frequency of letters.
        char t;       
    while(!myfile.eof()){     
        while(myfile.get(t)){
            if(isupper(t)){    
                int i = 0;
                do{
                    array[tolower(t)-'a']++;
                    i++;
                }
            while(i &lt; 26);
            }
        }
    int x = 0;
    while(x &lt; 26){
        cout &lt;&lt; 'a' + x &lt;&lt; ":" &lt;&lt; array[x] &lt;&lt; endl;
        x++;
    }
    }
    }
    }
return 0;
}
</code></pre>
