searchctot.c (876B)
1 /* Exercise 8.19 */ 2 3 #include <stdio.h> 4 #include <string.h> 5 #include <stdlib.h> 6 #include <ctype.h> 7 8 #define STRINGS 10 9 #define BUF 254 10 #define ASCII 127 11 12 int main(void) 13 { 14 char string[STRINGS][BUF] = { { 0 } }; 15 int i = 0, j, counter[ASCII] = { 0 }; 16 17 /* Take the strings */ 18 printf("Give me a string (%d to end): ", EOF); 19 gets(string[i]); 20 21 while( atoi(string[i++]) != EOF ) { 22 printf("Give me a string (%d to end): ", EOF); 23 gets(string[i]); 24 } 25 26 string[i - 1][0] = '\0'; /* Remove the '-1' */ 27 28 for(i = 0; i < STRINGS; i++) { 29 for(j = 0; (unsigned)j < strlen(string[i]); j++) { 30 ++counter[tolower((int)string[i][j])]; 31 } 32 } 33 34 for(i = 1; i < ASCII; i++) { 35 if(counter[i]) { 36 37 i == 32 ? printf("spaces") : printf("%c", i); 38 39 printf("[%d] ", counter[i]); 40 } 41 } 42 printf("\n"); 43 44 return 0; 45 } /* E0F main */ 46