[Previous]
[Contents]
[Next]

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 from src to dest, swapping every pair of characters. The num argument should be even; if it isn't, num - 1 bytes are copied. This function 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

int main( void )
  {
    char buffer[80];

    printf( "%s\n", msg );
    memset( buffer, '\0', 80 );
    swab( msg, buffer, NBYTES );
    printf( "%s\n", buffer );
    return( EXIT_SUCCESS );
  }

produces the output:

hTsim seasegi  swspaep.d
This message is swapped.

Classification:

WATCOM

Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

[Previous]
[Contents]
[Next]