C语言编程之字符串排序

版权声明:此篇博文为博主心血o(╥﹏╥)o,如要转载请注明来源,勿忘心安! https://blog.csdn.net/dyq1995/article/details/88413604

问题描述:使用C语言编程实现对字符串排序。

程序源码:

#include<stdio.h>
void main()
{
char *str1[20],*str2[20],*str3[20];
char swap();
printf("please input three strings\n");
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",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("after being sorted\n");
printf("%s\n%s\n%s\n",str1,str2,str3);
}
char swap(p1,p2)
char *p1,*p2;
{
char *p[20];
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}

猜你喜欢

转载自blog.csdn.net/dyq1995/article/details/88413604