/* Programmer: Greg Perkins Program: letter_count.c Class: CS 73 C/UNIX Due: 12 February 1998 This program accepts data from standard input and reports the number of times that letters are repeated. It outputs the number of times repeated characters occurred. A character is counted as repeated even if whitespace or punctuation falls between it and the next occurrence of the letter. The character is not counted as repeated when other alphanumeric characters follow it. */ #include #include int main() { int count = 0; int new_char, prev_char = -999; /* -999 indicates first character */ while ((new_char = getchar()) != EOF) { /* consider upper & lowercase letters as equal */ if (isalpha(new_char)) new_char = tolower(new_char); if (prev_char != -999) /* if past first character */ { /* if new_char is not whitespace or punctuation check repeat */ if(isalnum(new_char)) if (new_char == prev_char) count++; else prev_char = new_char; } else prev_char = new_char; } printf("\nThe number of repeated characters was %d.\n", count); return (0); }