swab
void  swab ( char * src, char * dest, int num );
stdlib.h
  cplusplus.com  

Swap bytes.
  Swaps num bytes of src by pairs and stores the result in dest. Useful to change byte order (lower order byte becomes higher, and higher becomes lower) in order to exchange binary data with a machine that uses a different byte order on 2-bytes data types.

Parameters.

src
Address of data to be swapped
dest
Destination location for the swapped data.
num
Number of bytes to be swapped.

Return Value.
  (none)

Portability.
  Not defined in ANSI-C. Supported by some compilers.

Example.

/* swab example */
#include <stdio.h>
#include <stdlib.h>

/* global arrays: destination[] initialized with zeros */
char source [7] = "ABCDEF";
char destination [7];

main ()
{
  swab (source, destination, 6);
  printf ("swab: %s -> %s\n", source, destination);
  return 0;
}

See also.
  atof, strtol, strtoul


© The C++ Resources Network, 2000