被指针弄糊涂的菜鸟
输入三个字符串 比较大小 从小到大顺序输出
我的程序得出的结果惨不忍堵 请熟手指点
#include <stdio.h>
swap(int *p1,int *p2)
{ int temp;
temp=*p1;
*p1=*p2;
*p2=temp;
}
exchange(int *m,int *n,int *s,int *a,int *b,int *c)
{ if(*m>*n)
swap(m,n);
swap(a,b);
if(*m>*s)
swap(m,s);
swap(a,c);
if(*n>*s)
swap(n,s);
swap(b,c);
}
main()
{ int a[100],b[100],c[100],*p_a,*p_b,*p_c;
int *sum1,*sum2,*sum3,sum_1,sum_2,sum_3;
sum1=&sum_1,sum2=&sum_2,sum3=&sum_3;/*三个指针分别指向三个统计的变量*/
sum_1=0,sum_2=0,sum_3=0;
p_a=a,p_b=b,p_c=c;
printf("input the first string:");
while((*p_a=getchar())!='\n');
{ sum_1=sum_1+*p_a;
p_a++;
}
printf("input the second string:");
while((*p_b=getchar())!='\n')
{
sum_2=sum_2+*p_b;
p_b++;
}
printf("input the third string:");
while((*p_c=getchar())!='\n')
{
sum_3=sum_3+*p_c;
p_c++;
}
p_a=a,p_b=b,p_c=c; /*让指针重新指向三个字符串的首位*/
exchange(sum1,sum2,sum3,p_a,p_b,p_c);
printf("the largetst string: %d %s\n",sum1,a);
printf("the middle string: %d %s\n",sum2,b);
printf("the smallest string: %d %s\n",sum3,c);
}