Florii11

4

Jan 4th, 2021
134
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.  
  4. int main()
  5. {
  6.     FILE* fp=fopen("cuvinte_in.txt","r");
  7.     if(!fp)
  8.         return -1;
  9.     char *a=calloc(1000000,sizeof(char));
  10.     int i=0;
  11.     while(!feof(fp))
  12.     {
  13.         fscanf(fp,"%c",&a[i++]);
  14.     }
  15.     a=realloc(a,(i+1)*sizeof(char));
  16.     char*k=strtok(a," ,.\n\r");
  17.     char**cuv=calloc(1000000,sizeof(char*));
  18.     int ct=0;
  19.     while(k)
  20.     {
  21.         cuv[ct++]=k;
  22.         k=strtok(NULL," ,.\n\r");
  23.     }
  24.     for(int i=0;i<ct;i++)
  25.     for(int j=i+1;j<ct;j++)
  26.         if(strcmp(cuv[i],cuv[j])>0)
  27.     {
  28.         char*aux=cuv[i];
  29.         cuv[i]=cuv[j];
  30.         cuv[j]=aux;
  31.     }
  32.     for(int i=0;i<ct;i++)
  33.         printf("%s\n",cuv[i]);
  34.  
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment