#include <stdio.h>
#include<ctype.h>
main() {
	int c,nletters[26],i;	
	for (i = 0; i < 26; ++i)
		nletters[i] = 0;
	while ((c = getchar()) !='!') {
		if(isupper(c))
		c=tolower(c);
		++nletters[c - 'a'];			
	}
	for (i = 0; i < 26; ++i) {
		c = 'a' + i;
                  if(nletters[i] != 0){
		putchar(c);
		printf(" = %d\n", nletters[i]);}
	}
}

Nah, how about you ask a specific question about the part you don't understand? What do you think it does?

The above question is as follows.

Write a program to count the occurrence of letters in the range a - z and A - Z. Ignore other chars.

Output for input: aAbcBc

a = 2
b = 2
c = 2

The program accepts alphabets and maintains the count of occurance of each alphabet in one array (for all 26 letters).
But the range of alphabets considered here does not differentiate between lowercase [a-z] and uppercase [A-Z] and thus converts the uppercase entries also to lowercase to make the calculation simple.

isupper function checks for uppercase characters and tolower function converts it to lowercase.

Anyway your input should be aAbcBc! because the entry has to terminate with a "!" character. And the output you got tells the rest.

N.B: To meet your program requirements (as per your WAP statement) try to distinguish between lowercase and uppercase characters.

Hope you got it...

please note some small syntax changes i have made to your code. although they seem like a burden, this sort of correctness and neatness will make the code clearer and easier to understand. best of luck! ;)

#include <stdio.h>
#include <ctype.h>
int main() {
int c, nletters[26], i;	
	for (i = 0; i < 26; ++i)
		nletters[i] = 0;
	while ( (c = getchar()) != '!' ) {
		if (isupper(c))
		c=tolower(c);
		++nletters[c - 'a'];			
	}
	for (i = 0; i < 26; ++i) {
		c = 'a' + i;
                if(nletters[i] != 0) {
			putchar(c);
			printf(" = %d\n", nletters[i]);
		}
	}
return 0;
}
This article has been dead for over six months. Start a new discussion instead.