69,335
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
void swap(char *, char *); /*函数声明*/
void main()
{
char str1[20]={0},str2[20]={0},str3[20]={0}; /*字符数组就可以存放字符串了,干嘛还要定义字符指针数组?*/
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]={0};
strcpy(p,p1);
strcpy(p1,p2);
strcpy(p2,p);
}
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[20],str2[20],str3[20];
void swap();
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);
return 0;
}
void swap(char *p1,char *p2)
{
char p[20];
strcpy(p,p1);
strcpy(p1,p2);
strcpy(p2,p);
}
#include <stdio.h>
#include <string.h>
void main()
{
char str1[20], str2[20], str3[20];
void swap();
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);
}
void swap(char *p1,char *p2)
{
char p[20];
strcpy(p,p1);
strcpy(p1,p2);
strcpy(p2,p);
}