swab

swap bytes of a memory block

Synopsis:

#include <stdlib.h>
void swab( char *src, char *dest, int num );

Description:

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.

Examples:

#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.

Classification:

WATCOM

Systems:

All (except DOS/PM)