CS140 -- Midterm Exam: Q15 - Q16

Question 15: Write a program called larg that prints out the last character of every argument given on the command line.

Here are some examples:

UNIX> larg
UNIX> larg Jim Plank
m
k
UNIX>larg 1 2 3 4 50
1
2
3
4
0
UNIX> 
Question 16: Write a program revn that takes two command line arguments -- an integer n and a filename fn. It then makes the file fn, which is the first n lines of standard input in reverse order. You may not use the stacks library that we talked about in class on tuesday -- just use an array instead.

Here are some examples (I've bold-faced the output):

UNIX> revn
usage: revn n filename
UNIX> revn 10 f1 f2
usage: revn n filename
UNIX> revn 2 f1
Give
Him
Six!
< CNTL-D >
UNIX> cat f1
Him
Give
UNIX> revn 15 f2
Give
Him
Six!
< CNTL-D >
UNIX> cat f2
Six!
Him
Give
UNIX> revn Jim Plank
Bad value of n
UNIX> revn -3 f3
Bad value of n
UNIX>
The answer sheet has a skeleton of the code for you to fill in.

Obviously, if you can't do it all, do what you can so you can get partial credit. It helps in grading if you let me know what parts you didn't do.