Home > Back-end >  C enter an English word counts each of these letters and output
C enter an English word counts each of these letters and output

Time:05-08

Find a lot of code is statistics letters in a string of characters, Numbers, symbols such as the number of, don't know how to statistics the number of each letters in a string of characters in English,,, can help to write the code?

CodePudding user response:

Reference:
 # include 

Int main ()
{
Char s [256];
Int I=0, A [26]={0}, A [26]={0};
Gets (s);
While (s [I]) {
If (s [I] & gt;='A' & amp; & S [I] <='Z')
A [[I] - 'A' s] + +;
If (s [I] & gt;='a' & amp; & S [I] <='z')
A [[I] - 'a' s] + +;
i++;
}
for(i=0; i<26. I++)
Printf (" % [c], [c] % % d: % d \ n ", I, 'A' + A [I], 'A' + I, A [I]);

return 0;
}

CodePudding user response:

 # include 
#include

Int main ()
{
Char STR [128], * PSTR;
Int I=0, upper [26]={0}, the lower [26]={0};

The fgets (STR, sizeof (STR), stdin);

PSTR=STR;
While (* PSTR) {
If (isupper (* PSTR))
Upper [* PSTR - 'A'] + +;
Else if (islower (* PSTR))
The lower [* PSTR - 'a'] + +;

Pstr++;
}
for(i=0; i <26. I++)
Printf (" % [c], [c] % % d: % d \ n ", 'A' + I, upper [I], 'A' + I, lower [I]);

return 0;
}

For your reference ~
  • Related