复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include<stdio.h> #include<string.h> #define buffsize 100 void main() { char str[5][buffsize],t[buffsize];//str[5][100]表示5个能存放100字符的字符串 int i,j,k; //,一个二维字符数组,一个一维字符数组 for(i=0;i<5;) {printf("please input the string:%dn",i+1); gets(t); if(strlen(t)>100) { printf("the length of string is larger than 100n"); continue; } strcpy(str[i],t); i++; } //输入五串字符串,如果输入的字符串超过100字符则重输,否则依次输入五串字符串 for(j=0;j<5;j++) {k=j; for(i=j+1;i<5;i++) if(strcmp(str[k],str[i])>0) //比较字母asc码大小,字母越靠后asc码越大 k=i; if(k!=j) //以下重新进行排序处理 { strcpy(t,str[k]); strcpy(str[k],str[j]); strcpy(str[j],t); } } printf("n"); for(i=0;i<5;i++) printf("%sn",str[i]); getchar(); }
最后
以上就是精明鞋子最近收集整理的关于C中输入5个字符串,并将它们按字母顺序(升序)输出的全部内容,更多相关C中输入5个字符串内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复