|
|
c m s c 311
s p r i n g 2 0 0 3 |
Input is through input redirection. Output is through output redirection. Thus, read from standard input and write to standard output.
The hexdump is modelled after xxd. Try using xxd. Read the man pages for it too.
When the file is to be read from the command line, instead of standard input, it will always have a -i option. For a small amount of extra credit, you can assume that a name that sits by itself is the name of a file (as it was originally posted).
Think of a char as a one byte int. int's can either be signed or unsigned. While it's not specified whether char should be signed or unsigned, it's considered signed.
Thus, when you convert it to an int it may cause the value to stay negative.
For purposes of converting to hex, it's usually easier to
do the following:
void byteToHex( char byte, char * hexArray )
{
unsigned char byte2 = byte ; // Save as unsigned
}
that way casting byte2 to an unsigned int works
the way you expect it to.
These are valid/invalid combinations:
-i, -o and -w (in any order).
-i, -o and -w (in any order).
hexdump -z -ma -p -i foo.nameyou should output:
Unknown switch: -z Unknown switch: -ma 00 00 00 00 00 00 01 00 2E 64 79 6E 73 79 6D 00 2E 72 65 6C 2E 64 79 6E Total bytes: 24Many UNIX utilities tend to abort when there are unknown switches, so this is somewhat non-standard behavior to ignore unknown switches. The error messages are printed just so we can tell they are there.
If you can, try to avoid too much code duplication. In particular, there are nice ways to parameterize whether you are printing to a file or to standard output.
|
See the class syllabus for policies concerning email Last Modified: Fri Feb 14 09:13:38 EST 2003 |