看看我的程序有错百?C的

来源:百度知道 编辑:UC知道 时间:2024/06/02 18:39:02
main()
{char *str1[20],*str2[20],*str3[20];
char swap(char p1,char p2);
printf("Input three lines:\n");
gets(str1);
gets(str2);
gets(str3);

if(strcmp(str1,str2)>0)swap(str1,str2);
if(strcmp(str1,str3)>0)swap(str1,str3);
if(strcmp(str2,str3)>0)swap(str2,str3);
printf("Now,the order is:\n");
printf("%s\n%s\n%s\n",str1,str2,atr3);
}
char swap(char *p1,char *p2)
{char *p[20];
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}

你的程序有几个小问题,可能你对数组和指针没理解清楚,我给你修改如下:

main()
{char str1[20],str2[20],str3[20];
char swap(char p1[],char p2[]);
printf("Input three lines:\n");
gets(str1);
gets(str2);
gets(str3);

if(strcmp(str1,str2)>0)swap(str1,str2);
if(strcmp(str1,str3)>0)swap(str1,str3);
if(strcmp(str2,str3)>0)swap(str2,str3);
printf("Now,the order is:\n");
printf("%s\n%s\n%s\n",str1,str2,str3);
}
char swap(char p1[],char p2[])
{char p[20];
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}