C语言交换任意相同类型的值、交换两个字符串的指针

#include <stdio.h>
#include <string.h>

void swap(void * vp1, void * vp2, const int size) {
	char temp;
	for(int i = 0; i < size; i++) {
		temp = ((char *)vp1)[i];
		((char *)vp1)[i] = ((char *)vp2)[i];
		((char *)vp2)[i] = temp;
	}
}

void swap_str(char * vp1, char * vp2) {
	char ** temp = *vp1;
	*vp1 = *vp2;
	*vp2 = temp;
}

int main() {
	int a = 7;
	int b = 117;
	swap(&a, &b, sizeof(int));
	printf("a:%d b:%d\n", a, b);
	
	double c = 123.4;
	double d = 678.9;
	swap(&c, &d, sizeof(double));
	printf("c:%lf d:%lf\n", c, d);
	
	char * husband = strdup("Husband");
	char * wife = strdup("Wife");
	swap_str(&husband, &wife);
	printf("husband:%s wife:%s\n", husband, wife);
	swap_str(husband, wife);  // 错误的调用
	printf("husband:%s wife:%s\n", husband, wife);
}