|
发表于 2018-6-16 21:16:36
|
显示全部楼层
你想用指针操作
看代码,自己琢磨
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- void swap(char **p1,char **p2);
- char s1[40]={0},s2[40]={0},s3[40]={0};
- int a,b,c;
- char *p1, *p2, *p3;
- p1=s1;
- p2=s2;
- p3=s3;
- printf("Please enter the data:\n");
- gets(s1);
- gets(s2);
- gets(s3);
- printf("这三个字符串为:\n");
- puts(s1);
- puts(s2);
- puts(s3);
- printf("\n");
- a=strlen(s1);
- b=strlen(s2);
- c=strlen(s3);
- if(a<b) swap(&p1,&p2);
- if(a<c) swap(&p1,&p3);
- if(b<c) swap(&p2,&p3);
- printf("Now the string is:\n");
- printf("%s\n%s\n%s\n",p1,p2,p3);
- return 0;
- }
- void swap(char **p1,char **p2)
- {
- char *temp;
- temp=*p1;
- *p1=*p2;
- *p2=temp;
- }
复制代码 |
|