swab(3C)
_________________________________________________________________
swab function
Swap the bytes within each pair of bytes in a string.
_________________________________________________________________
Calling Sequence
char *string1, *string2;
int num;
swab(string1, string2, num);
where string1 contains the bytes to be swapped.
string2 contains the result of swapping.
num is the number of bytes to swap.
Description
Use the swab function to swap the bytes within each pair of bytes
in a string. The number of bytes to swap, num, should be even.
If, however, the number is odd, the Data General compiler will
take the value
(num - 1) instead of num. Note that it is unclear how other
compilers might act.
Returns
The swab function does not return a value.
Related Functions
See also the other string-handling functions. Chapter 1 lists
them all.
Example
/* Program test for the swab() function */
#include <stdio.h>
#define MAX 80
char string[MAX], *swab();
int length, strlen();
int i = 1;
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
swab(3C)
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
length = strlen(argv[i]);
swab(argv[i], string, length);
printf("'%s' ==> '%.@s'\n",
argv[i], length, string);
i++;
}
}
A call to the program test with
x test Swap these bytes.
generates the output
'Swap' ==> 'wSpa'
'these' ==> 'htsee'
'bytes.' ==> 'ybet.s'
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)