summaryrefslogtreecommitdiff
path: root/wk4/lect/copy.c
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-02-27 20:53:17 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-02-27 20:53:17 +0000
commitf2b4ff13009844b5ffa068108ec2f332ad02c7f2 (patch)
treeaa76dcbe1f0783181cefa5a6ef94fa34e9a74403 /wk4/lect/copy.c
parent1102dfd4322d9a62fb38c83aa70857ac29f171ef (diff)
Tue, Feb 27, 2024, 12:53 PM -08:00
Diffstat (limited to 'wk4/lect/copy.c')
-rw-r--r--wk4/lect/copy.c6
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];