swap bytes of a memory block
#include <stdlib.h> void swab( char *src, char *dest, int num );
The swab() function copies num bytes (which should be even) from src to dest, swapping every pair of characters. This is useful for preparing binary data to be transferred to another machine that has a different byte ordering.
#include <stdio.h> #include <string.h> #include <stdlib.h> char *msg = "hTsim seasegi swspaep.d"; #define NBYTES 24 void main() { char buffer[80]; printf( "%s\n", msg ); memset( buffer, '\0', 80 ); swab( msg, buffer, NBYTES ); printf( "%s\n", buffer ); }
produces the output:
hTsim seasegi swspaep.d This message is swapped.
WATCOM
All (except DOS/PM)