1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
/* ----------------------------- MNI Header -----------------------------------
@NAME : byte_swap.c
@INPUT : (none)
@OUTPUT : (none)
@DESCRIPTION: Reads bytes from standard input and writes the
swapped bytes standard output.
@METHOD :
@GLOBALS : (none)
@CALLS :
@CREATED : January 13,1991 (Peter Neelin)
@MODIFIED :
---------------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#define BYTES 2
#define ARRSIZE 800*BYTES
#define VALTYPE char
main()
{
VALTYPE input[ARRSIZE];
VALTYPE output[ARRSIZE];
int i,nread,extra;
while ((nread = fread(input, sizeof(VALTYPE),
sizeof(input)/sizeof(VALTYPE), stdin)) > 0) {
if ((extra = nread % BYTES) != 0) nread = nread-extra;
for (i=0; i < nread; i+=BYTES) {
output[i] = (VALTYPE) input[i+1];
output[i+1] = (VALTYPE) input[i];
}
(void) fwrite(output, sizeof(VALTYPE), nread, stdout);
}
return 0;
}
|