Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int string_compare(const void *p1, const void *p2) {
- return strcmp(*(char * const *) p1, *(char * const *) p2);
- }
- int main(void) {
- const int n = 10;
- char **a = (char **) malloc(n * sizeof(char *));
- for (int i = 0; i < n; i++) {
- a[i] = (char *) malloc(20);
- printf("%d > ", i + 1);
- scanf("%19s", a[i]);
- }
- qsort(a, n, sizeof(char *), string_compare);
- for (int i = 0; i < n; i++)
- printf("%d: %s\n", i + 1, a[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement