#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define N_STUDENTS 4
typedef unsigned char uchar;
typedef struct student_info {
char name[10];
int height;
float weight;
} student_info;
student_info students[N_STUDENTS] = {
{"À̼ø½Å", 172, 83.4},
{"È«±æµ¿", 167, 72.5},
{"±èÀ¯½Å", 159, 70.8},
{"À¯°ü¼ø", 163, 58.4}
};
int mystrcmp(const char* str1, const char* str2) {
for (int i = 0; ; i++) {
if ((uchar)str1[i] - (uchar)str2[i] < 0)
return -1;
else if ((uchar)str1[i] - (uchar)str2[i] > 0)
return +1;
if (str1[i] == 0 && str2[i] == 0) // || µµ µÊ (¿Ö µÉ±î »ý°¡Çغ¼ °Í)
return 0;
}
}
int find_min_byName(student_info data[], int start, int n)
{
int i, least;
least = start;
for (i = start + 1; i < n; i++) {
if (mystrcmp(data[i].name, data[least].name) < 0)
least = i;
}
return least;
}
void sort_byName(student_info data[], int n) {
student_info tmp;
int least;
for (int i = 0; i < n; i++) {
least = find_min_byName(data, i, n);
tmp = data[i];
data[i] = data[least];
data[least] = tmp;
}
}
void print_data(student_info s[], int n)
{
for (int i = 0; i < n; i++) {
printf("%s %d %f \n", s[i].name, s[i].height, s[i].weight);
}
}
int main(void)
{
printf("-----[Á¤·Ä Àü]-------\n");
print_data(students, N_STUDENTS);
sort_byName(students, N_STUDENTS);
printf("-----[Á¤·Ä ÈÄ]-------\n");
print_data(students, N_STUDENTS);
}