this will get you started
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int Occurences( char cAlpha, char* szString );
int main()
{
char szString[ 256 ];
strcpy( szString, "THis is a very long STRING and all characters WILL BE counted" );
char cAlpha = 'A';
for( int i = 0; i < 26;i++ )
{
cout << cAlpha << " occurs " << Occurences( cAlpha , szString )
<< " times in the string \"" << szString << "\""<< endl;
cAlpha++; // a + 1 = b and so on
}
return 0;
} // end
int Occurences( char cAlpha, char* szString )
{
// NULL pointer bad ju-ju
if( NULL == szString )
{
return 0;
}
int i = 0;
int nCount = 0;
do
{
//an Uppercase character + 32 is the lowercase of the character
//here we test for both.. more info on this look at an acii code chart
if( cAlpha == szString[ i ] || ( cAlpha + 32 ) == szString[ i ] )
nCount++;
i++;
}
while( NULL != szString[ i ] );
return nCount;
}