Patey

Untitled

Apr 13th, 2021
543
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. char **linii = NULL;
  8. int nr_linii = 0;
  9. int ok = 1;
  10.  
  11. char *linie()
  12. {
  13.     char ch;
  14.     char *cuvant = NULL, *p;
  15.     int nr_litere = 0;
  16.     while(1)
  17.     {
  18.         nr_litere++;
  19.         p = (char*)realloc(cuvant, nr_litere * sizeof(char));
  20.         /*if (p == NULL)
  21.         {
  22.             printf("\n\nMemorie insuficenta ! \n\n");
  23.             exit(EXIT_FAILURE);
  24.         }*/
  25.  
  26.         ch = getchar();
  27.         if (ch == '\n')
  28.             break;
  29.         cuvant = p;
  30.         cuvant[nr_litere - 1] = ch;
  31.     }
  32.     if (nr_litere > 1)
  33.         cuvant[nr_litere - 1] = '/0';
  34.     else
  35.         ok = 0;
  36.     return cuvant;
  37. }
  38.  
  39. int main()
  40. {
  41.     char **aux=NULL;
  42.     int i, j;
  43.     char *d;
  44.     char **linii2;
  45.  
  46.     for (;;)
  47.     {
  48.         nr_linii++;
  49.         linii2 = (char**)realloc(linii, nr_linii * sizeof(char*));
  50.         d = linie();
  51.         if (ok == 0)
  52.             break;
  53.         linii = linii2;
  54.         linii[nr_linii - 1] = d;
  55.     }
  56.  
  57.     printf("\n\nOrdonarea a fost efectuata !\n\n");
  58.  
  59.     for (i = 0; i < nr_linii - 2; i++)
  60.         for (int j = i + 1; j < nr_linii-1; j++)
  61.         {
  62.             if (strcmp(*(linii+j), *(linii+i)) > 0)
  63.             {
  64.                 strcpy(**aux, *(linii+j));
  65.                 strcpy(*(linii + j), *(linii + i));
  66.                 strcpy(*(linii + i), **aux);
  67.             }
  68.         }
  69.  
  70.     for (i = 0; i < nr_linii; i++)
  71.         printf("\n%s", *linii[i]);
  72.  
  73.  
  74. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×