#include
int main(int argc, char *argv[]) {
char line[1024];
char *ptr = NULL;
char *sch = NULL;
int count = 0, lcount = 0;
char *oddeven[] = { "even", "odd" };
if(argc != 2) {
fprintf(stderr, "Usage: cnchar CHAR < FILE\n");
return 0;
} else
sch = argv[1];
while(fgets(line, 1024, stdin) != NULL) {
lcount++;
for(ptr = line; *ptr; ptr++) {
if(*ptr == *sch)
count++;
}
if(count > 0) {
printf("%03d: `%c', occurences: %d, %s\n", lcount, *sch, count,
(count > 0 ? oddeven[count % 2] : " "));
count = 0;
}
}
return 0;
}