swab
swap adjacent bytes
You're viewing an older version of this page (#3506). View the current version.
INTERFACE
#include <string.h> void swab ( const void * restrict src, void * restrict dst, size_t len )
DESCRIPTION
The function swab copies len bytes from the location referenced by src to the location referenced by dst, swapping adjacent bytes. This is used to copy data from one machine to another with a different byte order.
The argument len must be an even number.
Example 1
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
const char* source="oCedoCsgi srgae t";
char target[18];
swab(source, target, strlen(source));
printf("swab(%s) becomes (%s)",source, target);
return 0;
}Output:
swab(oCedoCsgi srgae t) becomes (CodeCogs is great )SEE ALSO
HISTORY
A swab function appeared in Version 7 AT&T UNIX.