// Capitalizes a copy of a string while checking for errors #include #include #include #include int main(void) { // get a string char *s = get_string("s: "); if (!s) { return 1; } // allocate memory for another string char *t = malloc((strlen(s) + 1) * sizeof(char)); if (!t) { return 1; } // copy string into memory for (int i = 0, n = strlen(s); i <= n; i++) { t[i] = s[i]; } // capitalize first letter in copy if (strlen(t) > 0) { t[0] = toupper(t[0]); } // print strings printf("s: %s\n", s); printf("t: %s\n", t); // free memory free(t); return 0; }