/*--------------------------------------------------------------------*/ /* upper3.c */ /* Author: Bob Dondero */ /*--------------------------------------------------------------------*/ #include #include int main(void) /* Read text from stdin. Convert the first character of each "word" to uppercase, where a word is a sequence of alphanumeric characters. Write the result to stdout. Return 0. */ { int iChar; int iState = 0; while ((iChar = getchar()) != EOF) { switch (iState) { case 0: if (isdigit(iChar)) { putchar(iChar); iState = 1; } else if (isupper(iChar)) { putchar(iChar); iState = 1; } else if (islower(iChar)) { putchar(toupper(iChar)); iState = 1; } else { putchar(iChar); iState = 0; /* iState remains the same. */ } break; case 1: if (isalnum(iChar)) { putchar(iChar); iState = 1; /* iState remains the same. */ } else { putchar(iChar); iState = 0; } break; } } return 0; }