filter-ed.c (729B)
1 /* Exercise 8.24 */ 2 3 #include <stdio.h> 4 #include <string.h> 5 #include <stdlib.h> 6 #include <ctype.h> 7 8 #define SIZE 10 9 #define BUF 255 10 11 int main(void) 12 { 13 char strings[SIZE][BUF]; 14 int i = 0, j; 15 16 printf("Give me a string (%d to end): ", EOF); 17 gets(strings[i]); 18 19 while( atoi(strings[i++]) != EOF ) { 20 printf("Give me a string (%d to end): ", EOF); 21 gets(strings[i]); 22 23 for(j = 0; j < (int)strlen(strings[i]); j++) 24 strings[i][j] = tolower((int)strings[i][j]); 25 } 26 27 for(i = 0; i < SIZE; i++) { 28 /* If the current string terminate with "ed", then print it */ 29 if( !strncmp( &strings[i][ strlen(strings[i]) - 2 ], "ed", 2 ) ) 30 printf("%s\n", strings[i]); 31 } 32 33 return 0; 34 } /* E0F main */ 35