I have been given this assignment:
Write a complete program using two arrays, upper and lower to keep the upper
And lower alphabet respectively.
Ask the user to enter string example:
This is a test from Jupiter. Soon you will see who is from Jupiter!!! May be Dr. D.
Your program should parse the string and keep track of number of alphabet. Both arrays are indexed from 0 to 25. The logical way to do this is to use upper[0] to
Count the number of ‘A’, and upper[1] to count number of ‘B’ and so on. Likewise
For the lower array.
Output should look like:
A: 0 a:2
B: 0 b:0
This is what I have...
insert
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0};
printf("Enter a string:\t");
gets(string);
while ( string[c] != '\0' )
{
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
else if(string[c] >= 'A' && string[c] <= 'Z' )
count[string[c]-'A']++;
else
printf("ERROR!!\n");
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] != 0 )
printf("%c : %d\n",c+'a',count[c]);
}
return 0;
}
However, it does not differentiate between uppercase and lowercase letters, even though it must. Am I to create a separate variable for the uppercase? If yes, how do I implement it? If no, what should I do? Thanks