From f2b4ff13009844b5ffa068108ec2f332ad02c7f2 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:53:17 +0000 Subject: Tue, Feb 27, 2024, 12:53 PM -08:00 --- wk4/lect/copy.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'wk4/lect') 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]; -- cgit v1.2.3