diff options
Diffstat (limited to 'wk4')
-rw-r--r-- | wk4/lect/copy.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/wk4/lect/copy.c b/wk4/lect/copy.c index 4d442c5..a9ddd33 100644 --- a/wk4/lect/copy.c +++ b/wk4/lect/copy.c @@ -7,6 +7,10 @@ int main(void) { char *s = get_string("s: "); + if (s == NULL) + { + return 1; + } char *t = malloc(strlen(s) + 1); if (t == NULL) @@ -14,6 +18,8 @@ int main(void) return 1; } + strcpy(t,s); // copies a string s to a new string t + for (int i = 0, n = strlen(s); i <= n; i++) { t[i] = s[i]; |