Assignment 6: Shuffling
Complete assignment due: Thursday, Oct. 9th, 9 p.m.
Shuffle.
Write a C program named shuffle.c that will read pairs of lines from standard input. Each pair of lines will be shuffled: one letter from each line, starting with a character from the first line. The program will take two command-line arguments:
shuffle b|f <num>
A ‘b’ will print the characters backwards. An ‘f’ will print the characters forward. <num> will be the number of pairs of lines to process in the input.
Print a blank line after the result of the shuffle of each pair of lines.
After all pairs have been processed, print the number of each printable ASCII character that was present in the input. Print both the character and the count. For characters whose count is zero, skip the character and count. Print this summary by printing 8 characters per line with 8 counts on the next line. Use a field width of 7 for both the characters and the count.
Use the getchar() function to read input from standard input character-by-character.
Some examples:
$ cat sample1.txt            
Gettysburg Address
        Four-score and seven years ago, our
fathers brought forth on this
continent a new nation, conceived in liberty
and dedicated to the
$ ./shuffle f 1 < sample1.txt
G e t t y s b u rFgo uArd-dsrceosrse and seven years ago, our
 
Totals:
             ,      -      A      F      G      a      b
     14      1      1      1      1      1      3      1
      c      d      e      g      n      o      r      s
      1      3      6      2      2      4      6      6
      t      u      v      y
      2      3      1      2
$ ./shuffle b 2 < sample1.txt
srsueor d,doAg ag rsurbaseyyt tneeGves dna erocs-ruoF        
 
syithrte bniol  hntir odfe vtihegcunoorcb  ,snroeihttaanf wen a tnenitnoc
 
Totals:
             ,      -      A      F      G      a      b
     24      2      1      1      1      1      6      3
      c      d      e      f      g      h      i      l
      4      4     12      2      3      4      6      1
      n      o      r      s      t      u      v      w
     11     10     10      8     10      4      2      1
      y
      3
$
Practice using one-dimensional arrays is the main purpose of this program. You can assume that each line of input will have at most 1,000 characters before the newline character. You can also assume that the indicated number of pairs of lines will be present.
Your program is responsible for detecting three errors:
  1. missing command-line arguments. There should be exactly two command-line arguments.
  2. something other than a b or f as the first character of argument 1.
  3. the number of pairs of lines should be greater than 0.
If one of the above errors is detected, print the following usage statement to standard error:
Usage: shuffle b|f <num>
where <num> is greater than 0
and exit with a status of 1.
Turnin: Use the turnin program to turn in your completed shuffle.c program. The command is:
turnin 352assign6 shuffle.c
See the man page for the turnin program for details on what turnin can do and how you can confirm that your file was turned in.
Final Summary:
There is one file that you will need to turnin for full credit on this assignment:
shuffle.c