Write a c program that counts number of letters Solution

Write a c program that counts number of letters...

Write a program with a main() function and at least (3) functions definitions (and corresponding function prototypes and function calls). The program will:

1. read 1 character at a time until reaching EOF, (similar to the counting.c program)

2. use function getchar() to get one character from the user,

3. count the uppercase and lowercase letters of the alphabet, and

4. store the counts in an array of 26 elements.

5. The index of the array corresponds to each letter of the alphabet.
'a' will be index 0
'b' will be index 1
'c' will be index 2
etc.

6.The counts of each letter are stored as the elements of this array. This is similar to how an array is used to store the counts for the roll of a dice in this program: random2.c.

7. At end of program, print out the letters and counts.

8. Do NOT use 26 if-statements or a 26 case switch-statement in your code.

9. The array should be a local variable in the main() function. Make sure that you past your array to your functions. Below is an example main() function:

int main(){
//create array for 26 letters
int letters[SIZE] = {0};
printInstructions();
loopAndCountLetters(letters);
outputResults(letters, SIZE);
return 0;
}

Exmaple outputs:

This program will count the letters of the alphabet.
Type several sentences, or use input redirection to input a file.
To exit program, enter EOF (end of file) by pressing Crtl-D.
A
aa
BBB
bbbb
abcdef
ABCDEF
zZ
The character counts are:
a 5
b 9
c 2
d 2
e 2
f 2
g 0
h 0
i 0
j 0
k 0
l 0
m 0
n 0
o 0
p 0
q 0
r 0
s 0
t 0
u 0
v 0
w 0
x 0
y 0
z 2


This program will count the letters of the alphabet.
Type several sentences, or use input redirection to input a file.
To exit program, enter EOF (end of file) by pressing Crtl-D.
The quick brown fox jumps over the lazy dog.
The character counts are:
a 1
b 1
c 1
d 1
e 3
f 1
g 1
h 2
i 1
j 1
k 1
l 1
m 1
n 1
o 4
p 1
q 1
r 2
s 1
t 2
u 2
v 1
w 1
x 1
y 1
z 1
Powered by