Hello, part of my project I'm working on needs to have me count the amount of letters in a file. This is what I have so far. Any one help?

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
char c ; // start with a blank
int i;
int count[111] = {0};
int sum=0;
do
{start:
          c = cin.get() ;
           
         c = tolower(c);
		 {    

         {for(i = 97; i < 100; i++)
          { if (c==(char)i)
            {count[c]=sum++;
		 goto start;}
          }
		 }
         }
		 for(int x= 97; x < 100; x++)
		 {
			 cout<<(char)x<<" = "<<count[x]<<endl;
		 }
        
     }
    
     while (c != EOF) ;

return 0;
}

it can be done much easier: http://clipboard.it/v/XUb/

That is a good way to count a total of letters. Sorry I wasn't more specific. I need individual totals for the letters. I am only using a b and c for test purposes. Maybe I can extract elements of that program if I can't figure out how to make mine work.

An even easier way :Link

An even easier way :Link

yeah, but we dont want to count like \r\n ., etc..

Thank you for helping. Sorry I am so stubborn. My teacher may ask me to explain my code and I prefer to use code that I can grasp. I think I have got it to work. Take a look and see if there are any holes I don't see.

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
char c ; 
int i;
int sum[26] = {0};
do
{start:
          c = cin.get() ;
           
         c = tolower(c);
		 {    

         {for(i = 97; i < 123; i++)
          { if (c==(char)i)
            {sum[c-97]++;
		 goto start;}
          }
		 }
         }
		 for(int x= 97; x < 123; x++)
		 {
			 cout<<(char)x<<" "<<sum[x-97]<<endl;
		 }
        
     }
    
     while (c != EOF) ;

return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.