Export (0) Print
Expand All
div
eof
Expand Minimize

_swab 

Swaps bytes.


void _swab(
   char *src,
   char *dest,
   int n 
);

Parameters

src

Data to be copied and swapped.

dest

Storage location for swapped data.

n

Number of bytes to be copied and swapped.

If n is even, the _swab function copies n bytes from src, swaps each pair of adjacent bytes, and stores the result at dest. If n is odd, _swab copies and swaps the first n-1 bytes of src. _swab is typically used to prepare binary data for transfer to a machine that uses a different byte order.

Routine Required header Compatibility

_swab

<stdlib.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_swab.c

#include <stdlib.h>
#include <stdio.h>

char from[] = "BADCFEHGJILKNMPORQTSVUXWZY";
char to[] =   "..........................";

int main()
{
    printf( "Before: %s\n        %s\n\n", from, to );
    _swab( from, to, sizeof( from ) );
    printf( "After:  %s\n        %s\n\n", from, to );
}

Output

Before: BADCFEHGJILKNMPORQTSVUXWZY
        ..........................

After:  BADCFEHGJILKNMPORQTSVUXWZY
        ABCDEFGHIJKLMNOPQRSTUVWXYZ

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Community Additions

ADD
Show:
© 2014 Microsoft