//实现英文字符串进行字典排序 |
#include <stdio.h> |
#include <string.h> |
void sort( char str[][100]) |
{ |
int i, j; |
char temp[100]; |
//冒泡排序 |
for (i = 0; i < 9; i++) |
{ |
for (j = i + 1; j < 10; j++) |
{ |
if ( strcmp (str[i], str[j]) == 1) |
{ |
strcpy (temp, str[i]); |
strcpy (str[i], str[j]); |
strcpy (str[j], temp); |
} |
} |
} |
} |
int main() |
{ |
char str[10][100]; |
int i; |
printf ( "Please input a 10 string: \n" ); |
for (i = 0; i < 10; i++) |
{ |
printf ( "string %d : " , i + 1); |
fgets (str[i], 100, stdin); |
} |
sort(str); |
for (i = 0; i < 10; i++) |
printf ( "%s\n" , str[i]); |
return 0; |
} |
by: 发表于:2017-08-14 11:28:55 顶(0) | 踩(0) 回复
??
回复评论