|
|
1.1 ! root 1: #print ! 2: Write a function named "rev(s)" which reverses ! 3: the string "s" in place. Name the file that contains ! 4: the function "rev.c". ! 5: When you're satisfied, type "ready". ! 6: #once #create Ref ! 7: cbax0987654321 ! 8: #once #create tzaqc.c ! 9: main(){ ! 10: char *s1, *s2, *s3, *s4; ! 11: s1 = "abc"; ! 12: s2 = "x"; ! 13: s3 = ""; ! 14: s4 = "1234567890"; ! 15: rev(s1); ! 16: rev(s2); ! 17: rev(s3); ! 18: rev(s4); ! 19: printf(s1); ! 20: printf(s2); ! 21: printf(s3); ! 22: printf(s4); ! 23: printf("\n"); ! 24: } ! 25: #user ! 26: cc tzaqc.c rev.o ! 27: a.out >value ! 28: #cmp value Ref ! 29: #succeed ! 30: /* One way:*/ ! 31: ! 32: rev (s) ! 33: char *s; ! 34: { ! 35: char *p; ! 36: int t; ! 37: ! 38: for (p=s; *p; p++) ! 39: ; ! 40: for (p--; p > s; p--, s++) { ! 41: t = *p; ! 42: *p = *s; ! 43: *s = t; ! 44: } ! 45: } ! 46: #log ! 47: #next ! 48: 32.1a 10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.