/** * capitalize-0.c * * David J. Malan * malan@harvard.edu * * Capitalizes a given string. * * Demonstrates casting and iteration over strings as arrays of chars. */ #include #include #include int main(void) { // get line of text string s = GetString(); // capitalize text for (int i = 0, n = strlen(s); i < n; i++) { if (s[i] >= 'a' && s[i] <= 'z') { printf("%c", s[i] - ('a' - 'A')); } else { printf("%c", s[i]); } } printf("\n"); }