My code is currently reads in a string of lower case letters, identifying the occurrence of each letter.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char string[256];
int y = 0, num[26] = {0};
printf("Please enter the required string\n");
fgets(string, 256, stdin);
while (string[y] !='\0')
{
if (string[y] >= 'a' && string[y] <= 'z' )
num[string[y]-'a']++;
y++;
}
for ( y = 0 ; y < 26 ; y++ )
{
if( num[y] != 0 )
printf("%c occurs %d times in the entered string.\n",y+'a',num[y]);
}
return 0;
}
My issue is that I want my code to read uppercase and special symbols. showing the occurrence of both.
I have an idea:
Code:
else if(str[x] >= 'a' && str[x] <= 'z');
else if(str[x] >= '0' && str[x] <= '9');
However I struggle to implement it, any help would be appreciated.