函数功能: 交换字符串中相邻两个字节。
函数原型: void _swab( char *src, char *dest, int n );
参数介绍: char *src: 要拷贝、转换的字符串,char *dest,转换后存储到dest所表示的字符串, int n要拷贝、转换的字节数。
所属库: stdlib.h
示例一:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char hello[] = "Hello world!";
char temp[32];
memset(temp, 0, sizeof(temp));
swab(hello, temp, strlen(hello));
puts(temp);
swab(temp, temp, strlen(temp));
puts(temp);
return 0;
}
eHll oowlr!d
Hello world!
Press any key to continue
示例二:
如果把示例一中用到的原始字符串改为: char hello[] = "Hello world"; 则结果是:
eHll oowlr
Hello worl
Press any key to continue
可见丢失了一个d。