swab

Copies bytes (which must be an even number of bytes) from a source buffer to a destination buffer, swapping every pair of characters

Local Servers:nonblocking
Remote Servers:N/A
Classification:Other
Service:String Manipulation

Syntax

  For CLIB V 4.11 or above: 
   
  #include <string.h>  
   
  void swab  (  
     cinst void   *src,   
     void         *dst,   
     size_t        n);
  
  For all other CLIB versions: 
   
  #include <string.h>  
   
  void swab  (  
     char   *src,   
     char   *dst,   
     int    *n);
  

Parameters

src
(IN) Points to the string to be transformed.
dst
(OUT) Points to the array into which to place the transformed characters.
n
(IN) Specifies the number of characters to transform.

Return Values

None

Remarks

The swab function copies n bytes (which should be even) from src to dst swapping every pair of characters. This is useful for preparing binary data to be transferred to another machine that has a different byte ordering.

WARNING:The bytes copied must be of an even number, or the server will abend.

Example

  #include <string.h>  
  #include <stdio.h>  
   
  char *msg = "hTsim seasegi  swspaep.d";  
  #define NBYTES 24  
   
  main()  
  {  
     auto char buffer[80];  
     printf( "%s\n", msg );  
     memset( buffer, `\0’, 80 );  
     swab( msg, buffer, NBYTES );  
     printf( "%s\n", buffer );  
  }
  

produces the following:

  hTsim seasegi  swspaep.d  
  This message is swapped.