assignment-s-08.c (1035B)
1 /* Write a program that counts the number of occurrences of each alphabet (A-Z, a-z) in 2 the text entered using Command-Line Arguments. */ 3 4 #include <stdio.h> 5 #include <string.h> 6 7 int main(int argc, char *argv[]) 8 { 9 int target[2], i, j, count[2], len; 10 for (target[0] = 'A', target[1] = 'a'; target[0] <= 'Z', target[1] <= 'z'; target[0]++, target[1]++) 11 { 12 count[0] = 0; 13 count[1] = 0; 14 for (i = 1; i < argc; i++) 15 { 16 len = strlen(argv[i]); 17 for (j = 0; j < len; j++) 18 { 19 if (argv[i][j] == target[0]) 20 { 21 count[0]++; 22 } 23 if (argv[i][j] == target[1]) 24 { 25 count[1]++; 26 } 27 } 28 } 29 if (count[0]) 30 { 31 printf("\n\"%c\" found %d times.", target[0], count[0]); 32 } 33 if (count[1]) 34 { 35 printf("\n\"%c\" found %d times.", target[1], count[1]); 36 } 37 } 38 return 0; 39 }