cat.c
unknown
plain_text
2 years ago
922 B
8
Indexable
#include <stdio.h> #include <ctype.h> #include <string.h> int compare(char *name1, char *name2) { char n1[1001], n2[1001]; int i = 0; while (name1[i] != '\0') { n1[i] = tolower(name1[i]); i++; } n1[i] = '\0'; i = 0; while (name2[i] != '\0') { n2[i] = tolower(name2[i]); i++; } n2[i] = '\0'; return strcmp(n1, n2); } void sort(char names[][21], int n) { char temp[1001]; for (int i = 0; i < n - 1; i++) for (int j = 0; j < n - i - 1; j++) if (compare(names[j], names[j + 1]) > 0) { strcpy(temp, names[j]); strcpy(names[j], names[j + 1]); strcpy(names[j + 1], temp); } } int main() { char names[1001][21]; int n = 0; while (scanf("%s", names[n]) != EOF) n++; sort(names, n); for (int i = 0; i < n; i++) puts(names[i]); return 0; }
Editor is loading...
Leave a Comment