Back to DFS's C Page


OAC Problem Set II

Files

  1. Take the file-copy program in the File Access and add bulletproofing. Check the man pages for fopen() and fclose().
  2. In groups determined in class, create a program that will display the hexadecimal values and ASCII characters of the contents of a file. Each output should display a block of 256 bytes and look like the following:
    HEX DUMP: filecopy.c
    0000  2F 2A 20 43  6F 70 79 20  61 20 66 69  6C 65 20 2A  /* C opy  a fi le *
    0010  2F 0A 23 69  6E 63 6C 75  64 65 20 3C  73 74 64 69  /_#i nclu de < stdi
    0020  6F 2E 68 3E  0A 0A 76 6F  69 64 20 6D  61 69 6E 28  o.h> __vo id m ain(
    0030  29 0A 7B 0A  20 20 20 69  6E 74 20 63  68 3B 20 2F  )_{_    i nt c h; /
    0040  2A 20 69 6E  70 75 74 20  63 68 61 72  61 63 74 65  * in put  char acte
    0050  72 20 2A 2F  0A 20 20 20  63 68 61 72  20 69 6E 70  r */ _    char inp
    0060  75 74 66 69  6C 65 5B 38  30 5D 2C 20  6F 75 74 70  utfi le[8 0], outp
    0070  75 74 66 69  6C 65 5B 38  30 5D 3B 0A  20 20 20 46  utfi le[8 0];_ F
    0080  49 4C 45 20  2A 66 70 69  6E 2C 20 2A  66 70 6F 75  ILE  *fpi n, * fpou
    0090  74 3B 20 2F  2A 20 69 6E  70 75 74 20  26 20 6F 75  t; / * in put  & ou
    00A0  74 70 75 74  20 73 74 72  75 63 74 20  70 6F 69 6E  tput  str uct poin
    00B0  74 65 72 73  20 2A 2F 0A  0A 20 20 20  70 72 69 6E  ters  */_ _ prin
    00C0  74 66 28 22  57 68 61 74  20 66 69 6C  65 20 64 6F  tf(" What  fil e do
    00D0  20 79 6F 75  20 77 61 6E  74 20 74 6F  20 63 6F 70   you  wan t to cop
    00E0  79 3F 20 22  29 3B 0A 20  20 20 73 63  61 6E 66 28  y? " );_    sc anf(       
    00F0  22 25 73 22  2C 20 69 6E  70 75 74 66  69 6C 65 29  "%s" , in putf ile)
    Type:
     n for Next 256 bytes
     p for Previous 256 bytes
     q to Quit.
    

    Your program should have the following characteristics:


Created 7 Nov 98
Revised 19 Nov 1998
© DFStermole 1998