Syntax
#include <stdlib.h> void swab(char *source, char *destination, int n);Description
swab copies n bytes from source, swaps each pair of adjacent bytes, and stores the result at destination. The integer n should be an even number to allow for swapping. If n is an odd number, a null character (\0) is added after the last byte.
swab is typically used to prepare binary data for transfer to a machine that uses a different byte order.
Note: In earlier releases of C Set ++, swab began with an underscore (_swab). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, The Developer's Toolkit will map _swab to swab for you.
There is no return value.
This example copies n bytes from one location to another, swapping each pair of adjacent bytes:
#include <stdlib.h> #include <stdio.h> int main(void) { char from[20] = "hTsii s atsirgn..x "; char to[20]; swab(from, to, 19); /* swap bytes */ printf("%s\n", to); return 0; /**************************************************************************** The output should be: This is a string.. ****************************************************************************/ }Related Information