Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- // ABC sorrend
- int String_Comparer(const void *a, const void *b)
- {
- return strcmp(*(char**)a,*(char**)b);
- }
- // Hossz szerinti növekvő sorrend
- int String_Length_Comparer(const void *a, const void *b)
- {
- return strlen(*(char**)a) - strlen(*(char**)b);
- }
- int main()
- {
- char **names;
- int n, i;
- scanf("%d", &n);
- names = (char**)malloc(n * sizeof(char*));
- for(i = 0; i < n ; ++i)
- {
- char str[100];
- scanf("%s", str);
- names[i] = (char*)malloc(strlen(str) + 1);
- strcpy(names[i], str);
- }
- qsort(names, n, sizeof(char*), String_Length_Comparer);
- for(i = 0; i < n ; ++i)
- printf("%s\t", names[i]);
- for(i = 0; i < n ; ++i)
- free(names[i]);
- free(names);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement