-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW57.cpp
49 lines (47 loc) · 940 Bytes
/
HW57.cpp
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
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<string.h>
#pragma warning (disable : 4996)
void inputChar(char (*)[20],int);
void sort(char(*)[20], int);
void printfResult(char(*)[20], int);
int main()
{
char str[5][20];
int row = sizeof(str) / sizeof(str[20]);
inputChar(str, row);
sort(str, row);
printfResult(str, row);
return 0;
}
void inputChar(char(*str)[20], int row)
{
int i;
for (i = 0; i < row; i++) {
printf("# %d¹ø ¹®ÀÚ¿À» ÀÔ·ÂÇϽÿÀ : ",i+1);
scanf("%s",str[i]);
}
printf("\n");
}
void sort(char(*str)[20], int row)
{
int i,j,n;
char temp[20];
for (i = 0; i < row; i++) {
for (j = i; j < row; j++) {
n = strcmp(str[i], str[j]);
if (n > 0) {
strcpy(temp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], temp);
}
}
}
}
void printfResult(char(*str)[20], int row)
{
int i,len;
for (i = 0; i < row; i++) {
len = strlen(str[i]);
printf("str[%d] = %s %c %c\n",i,str[i], str[i][0],str[i][len-1]);
}
}