我想通过指针实现字符串数组在函数中的比较和排序,这种思路是有问题的吗,为什么会行不通呀

我想通过指针实现字符串数组在函数中的比较和排序,这种思路是有问题的吗,为什么会行不通呀

问题描述:

#include<stdio.h>
#include<string.h>
change(char (*p1)[],char (*p2)[])                //将两个字符串的值交换
{
  char t[100];
  strcpy(t,*p1);
  strcpy(*p1,*p2);
  strcpy(*p2,t);
}

compare(char (*p1)[],char (*p2)[],char (*p3)[])      //比较三个字符串的大小,并通过change函数调换顺序
{
  if(strcmp(*p1,*p2)>0)  change(p1,p2);
  if(strcmp(*p1,*p3)>0)  change(p1,p3);
  if(strcmp(*p2,*p3)>0)  change(p2,p3);
}

main()
{
  char a[100],b[100],c[100];
  char (*p1)[100]=&a,(*p2)[100]=&b,(*p3)[100]=&c;                 //让指针指向数组
  printf("Please enter three character string to be compare:\n");
  scanf("%s\n%s\n%s",p1,p2,p3);
  compare(p1,p2,p3);
  printf("These three character string are in order from smallest to largest is:\n");
  printf("%s\n%s\n%s\n",*p1,*p2,*p3);
}

 

下面是编译器报的一些问题,程序运行不出结果

以解决