Advertisement
Guest User

dziala

a guest
Jan 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N_MAX 100000
  6.  
  7. int compare(const void *a, const void *b)   /* funkcja uzywana przy qsort */
  8. {
  9.   return strcmp(*((char**)a), *((char**)b));
  10. }
  11.  
  12. int main()
  13. {
  14.   int i = 0, j;
  15.   char* Tekst[N_MAX];
  16.  
  17.   while (1)
  18.   {
  19.     char tab2[1000] = { 0 };
  20.  
  21.     if (fgets(tab2, 1000, stdin) == NULL)
  22.       break;   // on EOF fgets returns NULL
  23.  
  24.     tab2[strlen(tab2) - 1] = 0;   // get rid of \n at the end of the string
  25.  
  26.     Tekst[i] = (char*)malloc((strlen(tab2) + 1) * sizeof(char));
  27.     strcpy(Tekst[i], tab2);
  28.     i++;
  29.   }
  30.  
  31.   qsort(Tekst, i, sizeof(char *), compare);
  32.  
  33.   puts("\n\n");
  34.   for (j = 0; j<i; j++)
  35.   {
  36.     puts(Tekst[j]);
  37.   }
  38.   return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement