This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14202|Reply: 0

[C] Pointer method Input 3 strings and output them in order from smallest to largest

[Copy link]
Posted on 12/15/2015 2:24:01 PM | | |
//输入3个字符串,按由小到大的顺序输出

#include "stdafx.h"
#include "stdio.h"
#include "string.h"
int main()
{void paixu(char *,char *);
char str1[20],str2[31],str3[20];
printf("input three line:\n");
gets(str1);
gets(str2);
gets(str3);
if(strcmp(str1,str2)>0) paixu(str1,str2);
if(strcmp(str1,str3)>0) paixu(str1,str3);
if(strcmp(str2,str3)>0) paixu(str2,str3);  
printf("now,the order is:\n");
printf("%s\n%s\n%s\n",str1,str2,str3);
return 0;
}
void paixu(char *p1,char *p2)
{char p[20];
strcpy(p,p1); strcpy(p1,p2); strcpy(p2,p);
}

/*总结:1,string.h的头文件不能忘记
2. The get function is wrong is gets
3. strcpy is a copy function, and strcmp is a comparison function
*/




Previous:Pointer method Enter 10 numbers, swap the smallest number with the first number, and the largest number with the last number.
Next:Pointer method Input 3 integers and output them in order from smallest to largest
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com