I am working on a program that counts the number of characters in a string. It also counts and reports the number of times that each letter (a-z) is used. For reasons I can't figure out my program will only count and return lowercase letters.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0}, x, charcount = 0;
printf("Enter a string\n");
gets(string);
while (string[c] != '\0')
{
if (string[c] >= 'a'||'A' && string[c] <= 'z'||'Z')
{
x = string[c] - 'a';
count[x]++;
}
c++;
}
for(c = 0; c < strlen(string); c++)
{
if(string[c] !=' ')
{
charcount++;
}
}
printf("The string %s is %d characters long.\n", string, charcount);
for (c = 0; c < 26; c++)
{
if(count[c] != 0)
printf("%c %d \n", c + 'A', count[c]);
}
return 0;
}
Anyone know what I am doing wrong here?