#include <stdio.h>
#include <string.h>
void swap(char *p1, char *p2)
{
puts("交换前");
puts(p1);
puts(p2);
char *p0;
p0=p1;
p1=p2;
p2=p0;
puts("交换后");
puts(p1);
puts(p2);//在这个函数里是可以交换的
}
void check(char *a[])
{
char *temp;
if(strlen(a[0])<strlen(a[1]))
{
// temp=a[0];原来是这样的
// a[0]=a[1];可以实现交换
// a[1]=temp;我想添加一个交换的函数
swap(a[0], a[1]);
}
}
int main()
{
char source[2][10]={"Hel", "World"};
char *ptr[2];
int i;
for(i=0; i<2; i++)
ptr[i]=source[i];
check(ptr);
puts("最终结果");
for(i=0; i<2; i++)
puts(ptr[i]);//输出还是没有交换
return 0;
}
请问该如何修改以实现通过另一个函数进行交换?