summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L31.1a
diff options
context:
space:
mode:
authorIan Darwin <ian@cvs.openbsd.org>1998-09-28 16:01:29 +0000
committerIan Darwin <ian@cvs.openbsd.org>1998-09-28 16:01:29 +0000
commite9be7faad5fbf61edcad3700142615e315e407bc (patch)
tree5f3febafdfca4e38b83cbc129c87aefdece9ae70 /usr.bin/learn/lib/C/L31.1a
parent0436a5b6c19a613da918536b89a49cbcb38a2e4e (diff)
import BTL learn(1) lessons/C
Diffstat (limited to 'usr.bin/learn/lib/C/L31.1a')
-rw-r--r--usr.bin/learn/lib/C/L31.1a48
1 files changed, 48 insertions, 0 deletions
diff --git a/usr.bin/learn/lib/C/L31.1a b/usr.bin/learn/lib/C/L31.1a
new file mode 100644
index 00000000000..81d1bf9313b
--- /dev/null
+++ b/usr.bin/learn/lib/C/L31.1a
@@ -0,0 +1,48 @@
+#print
+Write a function named "rev(s)" which reverses
+the string "s" in place. Name the file that contains
+the function "rev.c".
+When you're satisfied, type "ready".
+#once #create Ref
+cbax0987654321
+#once #create tzaqc.c
+main(){
+ char *s1, *s2, *s3, *s4;
+ s1 = "abc";
+ s2 = "x";
+ s3 = "";
+ s4 = "1234567890";
+ rev(s1);
+ rev(s2);
+ rev(s3);
+ rev(s4);
+ printf(s1);
+ printf(s2);
+ printf(s3);
+ printf(s4);
+ printf("\n");
+}
+#user
+cc tzaqc.c rev.o
+a.out >value
+#cmp value Ref
+#succeed
+/* One way:*/
+
+rev (s)
+char *s;
+{
+ char *p;
+ int t;
+
+ for (p=s; *p; p++)
+ ;
+ for (p--; p > s; p--, s++) {
+ t = *p;
+ *p = *s;
+ *s = t;
+ }
+}
+#log
+#next
+32.1a 10