I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCString.h

swab

Swap adjacent bytes
+ View other versions (3)

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:

Example - Swap adjacent bytes
Workings
#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; 
}
Solution
Output:
swab(oCedoCsgi  srgae t) becomes (CodeCogs is great )

History

A swab function appeared in Version 7 AT&T UNIX.