- 论坛徽章:
- 0
|
下面是我的程序,但经常出错,有时正确,
#include <stdio.h>
#include <stdlib.h>
int compare(char **a, char **b)
{
char *c=NULL;
int i=0;
while((**(a+i)!='\0')&&(**(b+i)!='\0'))
{
if(**(a+i)>**(b+i))
{
return 0;
}
else
if(**(a+i)==**(b+i))
{
i=i+1;
continue;
}
else
{
c=*a;
*a=*b;
*b=c;
return 0;
}
i++;
}
if(**(a+i)!='\0')
{
c=*a;
*a=*b;
*b=c;
return 0;
}
else
return 0;
}
int main()
{
char a[100], b[100], c[100];
char **p, **q, **j;
char *t, *h, *m;
t=&a[0];
h=&b[0];
m=&c[0];
p=&t;
q=&h;
j=&m;
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
compare(p,q);
compare(p,j);
compare(q,j);
printf("%s\n",*p);
printf("%s\n",*q);
printf("%s\n",*j);
system("pause");
return 0;
} |
|