Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE* fp=fopen("cuvinte_in.txt","r");
- if(!fp)
- return -1;
- char *a=calloc(1000000,sizeof(char));
- int i=0;
- while(!feof(fp))
- {
- fscanf(fp,"%c",&a[i++]);
- }
- a=realloc(a,(i+1)*sizeof(char));
- char*k=strtok(a," ,.\n\r");
- char**cuv=calloc(1000000,sizeof(char*));
- int ct=0;
- while(k)
- {
- cuv[ct++]=k;
- k=strtok(NULL," ,.\n\r");
- }
- for(int i=0;i<ct;i++)
- for(int j=i+1;j<ct;j++)
- if(strcmp(cuv[i],cuv[j])>0)
- {
- char*aux=cuv[i];
- cuv[i]=cuv[j];
- cuv[j]=aux;
- }
- for(int i=0;i<ct;i++)
- printf("%s\n",cuv[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment