the code looks all messy at the moment, because i have been using this one to trial out different solutions to this problem.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
int limit = 0;
int i=0;
int x=0;
int y=0;
int a=0;
int b=0;
int c=0;
int nalpha=0;
const int MAX = 25;
int count[256] = {0};
int temp=0;
char userinput[MAX] = {'\0'};
int arry[50];
printf("Please enter a string up to 27 characters long. \n");
fgets(userinput, MAX, stdin);
userinput[strlen(userinput) - 1] = '\0';
for (a = 0; a<=MAX; a++)
{
userinput[a]=toupper(userinput[a]);
}
for (i = 0; i< MAX; i++)
{
printf("string entered: %d\n", userinput[i]);
}
for (b=0; b< MAX; b++)
{
if((userinput[b] <= 64) || (userinput[b] >= 91))
{
nalpha++;
}
else
{
count[userinput[b]]++;
}
}
for (y = 0; y<= MAX; y++)
{
printf("the tally for %c is %d \n", y + 'A', count[y]);
}
printf("there are %d none alphabetical characters", nalpha);
return(0);
}
E:>testcode
Please enter a string up to 27 characters long.
abc
string entered: 65
string entered: 66
string entered: 67
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
string entered: 0
the tally for A is 22
the tally for B is 0
the tally for C is 0
the tally for D is 0
the tally for E is 0
the tally for F is 0
the tally for G is 0
the tally for H is 0
the tally for I is 0
the tally for J is 0
the tally for K is 0
the tally for L is 0
the tally for M is 0
the tally for N is 0
the tally for O is 0
the tally for P is 0
the tally for Q is 0
the tally for R is 0
the tally for S is 0
the tally for T is 0
the tally for U is 0
the tally for V is 0
the tally for W is 0
the tally for X is 0
the tally for Y is 0
the tally for Z is 0
there are 0 none alphabetical characters
E:>