Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N_MAX 100000
- int compare(const void *a, const void *b) /* funkcja uzywana przy qsort */
- {
- return strcmp(*((char**)a), *((char**)b));
- }
- int main()
- {
- int i = 0, j;
- char* Tekst[N_MAX];
- while (1)
- {
- char tab2[1000] = { 0 };
- if (fgets(tab2, 1000, stdin) == NULL)
- break; // on EOF fgets returns NULL
- tab2[strlen(tab2) - 1] = 0; // get rid of \n at the end of the string
- Tekst[i] = (char*)malloc((strlen(tab2) + 1) * sizeof(char));
- strcpy(Tekst[i], tab2);
- i++;
- }
- qsort(Tekst, i, sizeof(char *), compare);
- puts("\n\n");
- for (j = 0; j<i; j++)
- {
- puts(Tekst[j]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement