Untitled
unknown
plain_text
a year ago
710 B
3
Indexable
Never
#include <cs50.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char *s = get_string("s: "); if (s == NULL) { return 1; } // Asks malloc for the bytes and t points to a random chunk of free space char *t = malloc(strlen(s) + 1); if (t == NULL) { return 1; } // +1 because you need the null character // for (int i = 0, n = strlen(s) + 1; i < n; i++) // { // t[i] = s[i]; // } strcpy(t, s); if (strlen(t) > 0) { t[0] = toupper(t[0]); } printf("s: %s\n", s); printf("t: %s\n", t); free(t); return 0; }