Created
November 11, 2020 00:59
-
-
Save caloni/5fe2767dbb36f769fe5e24ffd54d2c3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int cmpstr(void const *a, void const *b) | |
{ | |
const char const *aa = *(const char const **)a; | |
const char const *bb = *(const char const **)b; | |
return strcmp(aa, bb); | |
} | |
int main() | |
{ | |
char *names[] = { | |
"Liam", "Olivia", "Noah", "Emma", | |
"Oliver", "Ava", "William", "Sophia", | |
"Elijah", "Isabella", "James", "Charlotte", | |
"Benjamin", "Amelia", "Lucas", "Mia", | |
"Mason", "Harper", "Ethan", "Evelyn", | |
}; | |
size_t names_len = sizeof(names) / sizeof(char*); | |
int i; | |
qsort(names, names_len, sizeof(char*), cmpstr); | |
for( i = 0; i < names_len; ++i ) | |
{ | |
printf("%s\n", names[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment